UI中的表视图用法-创新互联
- (void)viewDidLoad {
专注于为中小企业提供做网站、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业襄汾免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
[super viewDidLoad];
self.data = @[@"Camping", @"Water Skiing", @"Weight Lifting", @"Stamp Collecting"];
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20) style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
// 设置表视图的头部视图
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 50)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width - 130)/2, 0, 150, 50)];
label.text = @"HeaderFooter";
label.textColor = [UIColor whiteColor];
[headerView addSubview:label];
headerView.backgroundColor = [UIColor cyanColor];
tableView.tableHeaderView = headerView;
[self.view addSubview:tableView];
}
#pragma mark -UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = (NSString *)self.data[indexPath.row];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return @"Johnny Appleseed";
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
return @"wrewrwer";
}
//自定义section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,0, 120)];
view.backgroundColor = [UIColor grayColor];
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 70, 70)];
imgView.backgroundColor = [UIColor lightGrayColor];
imgView.p_w_picpath = [UIImage p_w_picpathNamed:@"home_tab_icon_4.png"];
[view addSubview:imgView];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(85, 20, 200, 70)];
label.font = [UIFont boldSystemFontOfSize:16];
label.text = @"Johnny Appleseed";
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 80, 200, 50)];
label1.text = @"Hobby Information:";
[view addSubview:label1];
[view addSubview:label];
return view;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
//添加view
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 100)];
view.backgroundColor = [UIColor grayColor];
//添btn1
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 240)/3, 30, 120, 40);
[btn1 setTitle:@"Button1" forState:UIControlStateNormal];
[btn1 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
btn1.backgroundColor = [UIColor whiteColor];
[view addSubview:btn1];
//添加btn2
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
btn2.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 240)/3 *2 + 120, 30, 120, 40);
[btn2 setTitle:@"Button1" forState:UIControlStateNormal];
[btn2 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
btn2.backgroundColor = [UIColor whiteColor];
[view addSubview:btn2];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 120;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 100;
}
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
本文标题:UI中的表视图用法-创新互联
分享URL:http://myzitong.com/article/dihhcg.html