UITableView、  UITableViewCell

TableView:列表控件

TableView 是UIScrollView 的子类,所以说可以滚动
1.它分为两部分:
第一部分是:TableView
第二部分是:TableViewCell

TableView的基本设置

1.创建一个table
self.table = [[UITableViewalloc] initWithFrame: [UIScreenmainScreen].boundsstyle:UITableViewStyleGrouped];

2.给table设个背景
UIImageView *ImageviewBack = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds]
UIImage *viewBack = [UIImage imageNamed:@”0.jpeg”];
ImageviewBack.image = viewBack;
[self.table addSubview:ImageviewBack];
[self.table sendSubviewToBack:ImageviewBack];

3.设置分割线的颜色
self.table.separatorColor = [UIColor redColor];

4.设置分割线的样式
self.table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[self addSubview:self.table];

UITableViewCell

在Table中,每一个单元格叫cell
1、系统默认的提供了四种cell的样式
2、UItableViewCell默认已经声明好了三个控件(一个ImageView,两个label)

基本设置

1.设置背景颜色
cell.backgroundColor = [UIColor orangeColor];

2.添加文字
cell.textLabel.text = @“人在囧途”;

3.添加 说明文字
cell.detailTextLabel.text = @”人生亦是旅途,没有一帆风顺”;

4.添加头像
cell.imageView.image = [UIImage imageNamed:@”1.jpg”];

5.cell的选中提示效果
cell.selectionStyle = UITableViewCellSelectionStyleGray;

6.辅助视图
cell.accessoryType = UITableViewCellAccessoryCheckmark;//后面打对勾
cell.accessoryType = UITableViewCellAccessoryDetailButton;//后面添加button
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//”>”
。。。

7.在cell的后面添加View
UILabel *view = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
view.backgroundColor = [UIColor redColor];
view.layer.masksToBounds = YES;
view.layer.cornerRadius = 10;
view.text = @”3”;
view.textColor = [UIColor whiteColor];
view.textAlignment = NSTextAlignmentCenter;
cell.accessoryView = view;

8、
cell.textLabel.text = [NSString stringWithFormat:@”第%ld分区第%ld行”, indexPath.section, indexPath.row];

9.设置个人说明显示
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];

10.当cell被点击的时候会触发翻页(在controller.m里实现)(重要)只有在.m里调用了< UITableViewDelegate>才能使用页面跳转
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath{
SecondViewController *vc = [[SecondViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值