1. 程式人生 > >高仿人壽保險介面

高仿人壽保險介面

第一步 首先匯入第三方 gd
第二步 建立3個繼承於UIViewController的類 分別為
oneViewController twoViewController threeViewController
第三步 在ViewController.m裡
viewDidLoad [self createTabbar];
其次程式碼塊

-(void)createTabbar{
    NSArray *array = @[@"oneViewController",@"twoViewController",@"threeViewController"];
    //點選前的樣式
    NSArray *unSelectedImagerArray = @[@"首頁",@"金融超市",@"個人中心"];
    //點選後的樣式
    NSArray *SelectedImagerArray = @[@"首頁",@"金融超市",@"個人中心"];
    
    //控制器陣列
    NSMutableArray *ViewContro = [NSMutableArray new];
    
    //根據控制器的名稱建立響應的控制器 並新增到控制器的數組裡
    for (int i = 0; i<array.count; i++) {
        //string ----> Controller
        UIViewController *vc = [[NSClassFromString(array[i]) alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        //設定Tabbritem  的 選中圖片 未選中圖片 標題
        nav.tabBarItem.image = [[UIImage imageNamed:unSelectedImagerArray[i] ] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        nav.tabBarItem.selectedImage = [[UIImage imageNamed:SelectedImagerArray [i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        nav.title = unSelectedImagerArray[i];
        // nav.navigationBar.barTintColor = [UIColor blackColor];
        //新增到數組裡
        [ViewContro addObject:nav];
        
        
        
    }
    self.tabBar.barTintColor = [UIColor redColor];
    self.viewControllers = ViewContro;
    self.selectedIndex = 1;
}

第四步 在twoViewController.m裡

#import "CarouseView.h"
#import "CarouseViewPlus.h"
#define HCWidth self.view.frame.size.width
#define HCHeigth self.view.frame.size.height
<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,CarouseViewDataSource, CarouseViewDelegate>
{
    // 輪播圖變數,其實作為區域性變數也行
    CarouseView *carouseView;
    CarouseViewPlus *carouseViewPlus;
    
    // 輪播圖相關的資料
    NSArray *kvDataArray;
}

@property (nonatomic , strong)UICollectionView *clv;
@property (strong, nonatomic) UIView *contentView;
@property (strong, nonatomic) UIButton *popBtn;
@property (nonatomic, strong)UITableView *tbv;

viewDidLoad裡

[self gundong];
    [self.view addSubview:self.tbv];
    self.title = @"萬家燈火";
    self.navigationController.navigationBar.titleTextAttributes=
    @{NSForegroundColorAttributeName:[UIColor whiteColor],
      NSFontAttributeName:[UIFont systemFontOfSize:22]};
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];

程式碼塊:

-(UITableView *)tbv{
    if (!_tbv) {
        _tbv = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, HCWidth, HCHeigth) style:UITableViewStylePlain];
        _tbv.dataSource = self;
        _tbv.delegate = self;
    }
    return _tbv;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 4;
}
-(void)gundong{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 280)];
    // 新增輪播圖1
    kvDataArray = @[@"page 1", @"page 2", @"page3", @"page 4", @"page 5"];
    carouseView = [[CarouseView alloc] init];
    carouseView.frame = CGRectMake(0, 0, self.view.frame.size.width, 170);
    carouseView.datasource = self;
    carouseView.delegate = self;
    [headerView addSubview:carouseView];
    
    
    UIView * view  =[[UIView alloc]initWithFrame:CGRectMake(0, 170, self.view.frame.size.width, 110)];
    // view.backgroundColor = [UIColor blueColor];
    NSArray *arr  = @[@"11",@"22",@"33",@"44"];
    NSArray *arr1 = @[@"保險精品",@"課程精品",@"車險定製",@"關於我們"];
    for (int i = 0; i<arr.count; i++) {
        
        UIButton *bu = [[UIButton alloc]initWithFrame:CGRectMake(15 + 100*i, 10, 70, 70)];
        
        
        [bu setBackgroundImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
        
        [view addSubview:bu];
        UILabel *l1 = [[UILabel alloc]initWithFrame:CGRectMake(15 + 100*i, 85, 70, 20)];
        
        [l1 setText:arr1[i]];
        [view addSubview:l1];
        
    }
    [headerView addSubview:view];
    self.tbv.tableHeaderView = headerView;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        
    }
    
    if (indexPath.row == 0) {
        _tbv.rowHeight = 30;
        cell.textLabel.text = @"| 熱銷產品";
        cell.backgroundColor = [UIColor colorWithRed:255.0/255 green:196.0/255 blue:190.0/255 alpha:1];
    }else if(indexPath.row == 1){
        _tbv.rowHeight = 150;
        UIImageView *img1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
        img1.image = [UIImage imageNamed:@"aaaa"];
        [cell addSubview:img1];
    }else if (indexPath.row == 2){
        _tbv.rowHeight = 150;
        UIImageView *img2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
        img2.image = [UIImage imageNamed:@"bbbb"];
        [cell addSubview:img2];
    }else{
        _tbv.rowHeight = 150;
        UIImageView *img3 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
        img3.image = [UIImage imageNamed:@"cccc"];
        [cell addSubview:img3];
    }
    
    
    
    
    
    return cell;
}

#pragma mark - 輪播圖代理
- (NSInteger)countOfCellForCarouseView:(CarouseView *)carouseView
{
    return kvDataArray.count;
}

- (UIView *)carouselView:(CarouseView *)carouselView cellAtIndex:(NSInteger)index
{
    // 先用空白頁測試
    //    UIView *imageView = [[UIView alloc] init];
    //    int R = (arc4random() % 256) ;
    //    int G = (arc4random() % 256) ;
    //    int B = (arc4random() % 256) ;
    //    imageView.backgroundColor = [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1];
    
    // 填充view,可以是任意view
    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.jpg", (long)index + 1]];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 100, 50)];
    label.text = kvDataArray[index];
    [imageView addSubview:label];
    
    return imageView;
}

- (void)carouseView:(CarouseView *)carouseView didSelectedAtIndex:(NSInteger)index
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"carouse1 msg"
                                                        message:kvDataArray[index]
                                                       delegate:nil
                                              cancelButtonTitle:@"ok"
                                              otherButtonTitles:nil, nil];
    [alertView show];
}