tabbar控制器加子视图控制器
自定义cell以及自定义view还有网格的结合
#import "ONEViewController.h"
#import "CKSlideMenu.h"
#import "jinriViewController.h"
#import "yuleViewController.h"
#import "fuckViewController.h"
@interface ONEViewController ()
@end
@implementation ONEViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.automaticallyAdjustsScrollViewInsets = NO;
NSArray *titles = @[@"今日",@"阿萨德",@"爱迪生",@"暗示",@"说的",@"粉丝",@"阿萨德",@"爱迪生",@"暗示",@"说的"];
jinriViewController *ONE = [[jinriViewController alloc]init];
ONE.title = @"fff";
yuleViewController *Two = [[yuleViewController alloc]init];
Two.title = @"bbb";
NSArray *array = @[ONE,Two];
NSMutableArray *arr = [NSMutableArray array];
for (int i = 0; i <2 ; i++) {
[arr addObject:array[i]];
}
CKSlideMenu *slideMenu = [[CKSlideMenu alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width-60, 40) titles:titles controllers:arr];
slideMenu.bodyFrame = CGRectMake(0, 64+40, self.view.frame.size.width, self.view.frame.size.height-64-40);
[slideMenu scrollToIndex:3];
[self.view addSubview:slideMenu];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(360, 50, 60, 64)];
[btn setTitle:@"++++" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(abc) forControlEvents:UIControlEventAllEvents];
}
-(void)abc{
fuckViewController *fuck = [[fuckViewController alloc]init];
[self.navigationController pushViewController:fuck animated:YES];
}
@end
自定义view 网格
#import “zdy.h”
@implementation zdy
-(instancetype)initWithFrame:(CGRect)frame{
if (self== [super initWithFrame:frame]) {
[self vie];
}
return self;
}
-(void)vie{
NSArray *arr=@[@“1”,@“2”,@“3”,@“4”];
for ( int i=0; i<arr.count; i++) {
UIButton btn=[[UIButton alloc] initWithFrame:CGRectMake(7+100i, 0, 100, 80)];
[btn setBackgroundImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
btn.tag=100+i;
[self addSubview:btn];
}
}
@end
网格
#import “fuckViewController.h”
@interface fuckViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
UICollectionView *coll;
}
@end
@implementation fuckViewController
-
(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor orangeColor];
self.title=@“频道管理”;
//网格
UICollectionViewFlowLayout *fl=[[UICollectionViewFlowLayout alloc] init];
fl.minimumLineSpacing=0;
fl.minimumInteritemSpacing=0;
fl.itemSize=CGSizeMake(100, 100);coll=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:fl];
coll.delegate=self;
coll.dataSource=self;
[coll registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@“cell”];
coll.backgroundColor=[UIColor whiteColor];
[self.view addSubview:coll];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 16;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
NSArray *arr=@[@"11",@"22",@"33",@"44",@"55",@"66",@"77",@"88",@"111",@"1222",@"1333",@"1444",@"99",@"100",@"",@""];
UIView *vie=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300)];
UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
img.image=[UIImage imageNamed:arr[indexPath.row]];
[vie addSubview:img];
[cell addSubview:vie];
return cell;
}
//隐藏标签控制器
- (void)viewWillAppear:(BOOL)animated{
self.tabBarController.tabBar.hidden = YES;
} - (void)viewWillDisappear:(BOOL)animated{
self.tabBarController.tabBar.hidden = NO;
}
@end
子控制器显示表格
#import "jinriViewController.h"
#import "hahaTableViewCell.h"
#import "zdy.h"
@interface jinriViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic , strong) UITableView *tableview;
@property(nonatomic , strong) zdy *viewone;
@end
@implementation jinriViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.tableview];
self.tableview.tableHeaderView = self.viewone;
}
-(zdy *)viewone{
if (_viewone == nil) {
_viewone = [[zdy alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
}
return _viewone;
}
-(UITableView *)tableview{
if (_tableview == nil) {
_tableview = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
_tableview.delegate = self;
_tableview.dataSource = self;
[_tableview registerNib:[UINib nibWithNibName:@"hahaTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
}
return _tableview;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 8;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
hahaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
@"cell"];
self.tableview.rowHeight = 135;
return cell;
}
@end
#import "ONEViewController.h"
#import "CKSlideMenu.h"
#import "jinriViewController.h"
#import "yuleViewController.h"
#import "fuckViewController.h"
@interface ONEViewController ()
@end
@implementation ONEViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.automaticallyAdjustsScrollViewInsets = NO;
NSArray *titles = @[@"今日",@"阿萨德",@"爱迪生",@"暗示",@"说的",@"粉丝",@"阿萨德",@"爱迪生",@"暗示",@"说的"];
jinriViewController *ONE = [[jinriViewController alloc]init];
ONE.title = @"fff";
yuleViewController *Two = [[yuleViewController alloc]init];
Two.title = @"bbb";
NSArray *array = @[ONE,Two];
NSMutableArray *arr = [NSMutableArray array];
for (int i = 0; i <2 ; i++) {
[arr addObject:array[i]];
}
CKSlideMenu *slideMenu = [[CKSlideMenu alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width-60, 40) titles:titles controllers:arr];
slideMenu.bodyFrame = CGRectMake(0, 64+40, self.view.frame.size.width, self.view.frame.size.height-64-40);
[slideMenu scrollToIndex:3];
[self.view addSubview:slideMenu];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(360, 50, 60, 64)];
[btn setTitle:@"++++" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(abc) forControlEvents:UIControlEventAllEvents];
}
-(void)abc{
fuckViewController *fuck = [[fuckViewController alloc]init];
[self.navigationController pushViewController:fuck animated:YES];
}
@end