练习

2018-10-12  本文已影响0人  老公123

首先带入CKSlideMenu.h第三方库,然后在下面的操作

创建MainTabbar.h并且继承UITabBarController

#import "MainTabbar.h"

@interface MainTabbar ()

@end

@implementation MainTabbar

- (void)viewDidLoad {

    [super viewDidLoad];

    [self createTabBar];

}

- (void)createTabBar{

    NSArray *array=@[@"CKChildViewController",@"TwoViewController"];

    NSArray*UnSelectedImageArray=@[@"新闻",@"视频"];

//    NSArray *SelectedImageArray=@[@"新闻1",@"视频1"];

    //控制器数组

    NSMutableArray *ViewController=[[NSMutableArray alloc]init];

    //根据控制器的名称 创建相应的控制器 并添加到相应的数组里

    for(inti=0; i

        //字符串创建控制器

        UIViewController*VC=[[NSClassFromString(array[i])alloc]init];

        UINavigationController *NAV=[[UINavigationController alloc]initWithRootViewController:VC];

        //设置TabBar的选中图片和未选中图片

        NAV.tabBarItem.image=[[UIImage imageNamed:UnSelectedImageArray[i]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];

        NAV.title=UnSelectedImageArray[i];

        //将控制器添加到数组

        NAV.navigationBar.barTintColor=[UIColor blackColor];

        [ViewControlleraddObject:NAV];

    }

    self.viewControllers=ViewController;

}

@end

再创建CKChildViewController  继承UIViewController

/**  */

@property (nonatomic,assign)NSInteger type;

在.m里面写

#import "CKChildViewController.h"

#import "CKSlideMenu.h"

#import "CkViewController.h"

#import "TwoViewController.h"

#import "ckkenViewController.h"

@interface CKChildViewController ()

@end

@implementationCKChildViewController

-(void)viewDidAppear:(BOOL)animated{

    self.navigationController.navigationBar.hidden = YES;

}

-(void)viewWillDisappear:(BOOL)animated{

    self.navigationController.navigationBar.hidden = NO;

}

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

//    self.automaticallyAdjustsScrollViewInsets = NO;

        NSArray *titles = @[@"今日",@"阿萨德",@"爱迪生",@"暗示",@"说的",@"粉丝",@"阿萨德",@"爱迪生",@"暗示",@"说的"];

        NSMutableArray *arr = [NSMutableArray array];

        for(inti =0; i

            [arraddObject:[CkViewControllernew]];

        }

        CKSlideMenu*slideMenu = [[CKSlideMenualloc]initWithFrame:CGRectMake(0,30,self.view.frame.size.width-30,40)titles:titlescontrollers:arr];

        slideMenu.bodyFrame=CGRectMake(0,  64,self.view.frame.size.width,self.view.frame.size.height-30);

        [slideMenuscrollToIndex:3];

        [self.viewaddSubview:slideMenu];

    UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(380, 35, 30, 30)];

    [btnsetImage:[UIImage imageNamed:@"qq"] forState:UIControlStateNormal];

    [btnaddTarget:self action:@selector(els) forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:btn];

}

-(void)els{

    ckkenViewController *coy = [ckkenViewController new];

    [self.navigationController pushViewController:coy animated:YES];

}

写完并且还的创建它的跳转控制器

在创建CkViewController继承与UIViewController

#import "CkViewController.h"

#import "TwoViewController.h"

@interface CkViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView * tableView;

@end

@implementationCkViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    [self.viewaddSubview:self.tableView];

    //添加表格

    [self.viewaddSubview:self.tableView];

}

-(UITableView*)tableView{

    if (!_tableView) {

        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 720) style:UITableViewStylePlain];

        _tableView.delegate=self;

        _tableView.dataSource=self;

    }

    [self createTableHeaderView];

    return _tableView;

}

//每个分区有几行

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{

    return 5;

}

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

    staticNSString* str =@"123";

    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];

    if(!cell) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];

    }

    tableView.rowHeight=100;

    NSArray * arrone = @[@"宾利添越.兰博基尼Urus同平台!2.0T的新途锐哪款值得买",@"怦然心动!全新传祺GS5巴黎首秀 预售价12万起",@"一年年一度的豪车大甩卖开始了,哇塞,BBA都这么便宜了?",@"掏钱买车必看,2019年国六排放影响颇深...",@"主场作战还等着输给德国佬,巴西还能行吗?"];

    UILabel* labone = [[UILabelalloc]initWithFrame:CGRectMake(10,3,280,80)];

    labone.text= arrone[indexPath.row];

    labone.numberOfLines=0;

    [celladdSubview:labone];

    NSArray * arrtwo = @[@"大Car频道 102评论 3694次浏览 10分钟前",@"汽车探索 36评论 2925次浏览",@"车若初见 190评论 1712次浏览 32分钟前",@"车叫兽 52评论 1987浏览",@"车教授 88评论 1087浏览"];

    UILabel* labtwo = [[UILabelalloc]initWithFrame:CGRectMake(10,60,280,40)];

    labtwo.text= arrtwo[indexPath.row];

    labtwo.numberOfLines=0;

    labtwo.font= [UIFontsystemFontOfSize:13];

    labtwo.textColor= [UIColorlightGrayColor];

    [celladdSubview:labtwo];

    NSArray * arraythree = @[@"w1",@"w2",@"w3",@"w4",@"w5"];

    UIImageView* imgV = [[UIImageViewalloc]initWithFrame:CGRectMake(290,3,120,90)];

    imgV.image= [UIImageimageNamed:arraythree[indexPath.row]];

    [celladdSubview:imgV];

    returncell;

}

-(void)createTableHeaderView{

    UIView* bg = [[UIViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,100)];

    bg.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];

    NSArray * array = @[@"小仓说车",@"超级试驾",@"我的订阅",@"实用工具"];

    for(inti =0; i< array.count; i++) {

        UIButton* btn = [[UIButtonalloc]initWithFrame:CGRectMake(30+ ((self.view.frame.size.width-150)/4+30)*i,10, (self.view.frame.size.width-150)/4, (self.view.frame.size.width-150)/4)];

        //        [btn setBackgroundColor:[UIColor redColor]];

        NSArray* arrtu =@[@"q1",@"q2",@"q3",@"q4"];

        [btnsetImage:[UIImage imageNamed:arrtu[i]] forState:UIControlStateNormal];

        //        btn.layer.cornerRadius =((self.view.frame.size.width - 150)/4)/2;

        //        btn.layer.masksToBounds = YES;

        UILabel* label = [[UILabelalloc]initWithFrame:CGRectMake(30+ ((self.view.frame.size.width-150)/4+30)*i,25+ (self.view.frame.size.width-150)/4, (self.view.frame.size.width-150)/3,20)];

        label.textAlignment = NSTextAlignmentCenter;

        label.font= [UIFontsystemFontOfSize:15];

        label.textColor= [UIColordarkGrayColor];

        label.center=CGPointMake(btn.center.x,25+ (self.view.frame.size.width-150)/4);

        label.text= array[i];

        //添加label

        [bgaddSubview:label];

        //添加按钮

        [bgaddSubview:btn];

    }

    _tableView.tableHeaderView = bg;

}

@end

还需创建一个TwoViewController.h 另一个控制器

self.view.backgroundColor = [UIColor redColor];

上一篇 下一篇

猜你喜欢

热点阅读