【UITableView和UITableViewCell的常见属性 Objective-C语言】

一、UITableView和UITableViewCell的常见属性,

1.我们说,这些属性里面,

属性

2.这些是不是都是单元格的属性,

1)这个imageView:是单元格里面的图片框,是不是指的是这个啊,

2)这个textLabel:是指的这个标题上面这个Label吧,

3)这个detailTextLabel:是指的标题下面这个Label吧,

4)这个accessoryType:是指的,这个属性的数据类型是什么类型,是一个枚举类型,那么它有五种取值:

1> UITableViewCellAccessoryNone:每个单元格右边没有东西,

2> UITableViewCellAccessoryCheckmark:每个单元格右边是个对钩,

3> UITableViewCellAccessoryDisclosure:每个单元格右边是个小箭头,

4> UITableViewCellAccessoryDetailButton:每个单元格右边是个小圈i,

5> UITableViewCellAccessoryDislosureDetailButton:每个单元格右边既有小圈i,也有小箭头,

这个取值就是我们每一个单元格的右边这个符号的一个展示一些效果吧,

accessoryView

3.accessoryView:这个指的是什么,是不是就是指的也是右边这个符号,就是你可以自定义的吧,你可以给它任何一个UIView,都可以,你给它一个,比如说,开关,UISwitch,每个单元格右边就会显示一个开关,

4.backgroundView:

selectedBackgroundView:这两个都是设置背景的,

backgroundColor:这个一看就能猜出来,这是设置单元格的背景颜色,

我们给大家演示一下,在返回单元格的这个方法里面:

返回单元格

cell.backgroudColor = [UIColor blueColor];

蓝色

这样的话,每一个单元格的颜色,都变成蓝色的了,

蓝色

很难看吧,我写一个判断,

if(indexPath.row % 2 = = 0 ){

cell.backgroundColor = [UIColor blueColor];

} else {

cell.backgroundColor = [UIColor yellowColor];

}

蓝色

我们再运行,

蓝色

现在,不同的单元格是不是不同的颜色吧,

这个背景色是不一样的,

当我选中某一行的时候

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,让我为您展示一个简单的签到APP的首页的代码实现。 首先,我们需要创建一个包含签到按钮和签到记录的UITableView的视图控制器。我们可以使用以下代码创建一个基本的视图控制器: ``` #import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UIButton *checkInButton; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title = @"签到"; [self setupUI]; } - (void)setupUI { // 创建签到按钮 self.checkInButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 50)]; self.checkInButton.center = self.view.center; [self.checkInButton setTitle:@"签到" forState:UIControlStateNormal]; [self.checkInButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; self.checkInButton.backgroundColor = [UIColor blueColor]; [self.checkInButton addTarget:self action:@selector(checkInButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.checkInButton]; // 创建签到记录表格视图 self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.checkInButton.frame) + 20, self.view.frame.size.width, self.view.frame.size.height - CGRectGetMaxY(self.checkInButton.frame) - 20) style:UITableViewStylePlain]; self.tableView.delegate = self; self.tableView.dataSource = self; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; [self.view addSubview:self.tableView]; } - (void)checkInButtonClicked:(UIButton *)sender { // 处理签到逻辑 } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // 返回签到记录的数量 return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; // 显示签到记录 cell.textLabel.text = [NSString stringWithFormat:@"签到记录%ld", indexPath.row + 1]; return cell; } @end ``` 这个视图控制器包含一个签到按钮和一个签到记录的UITableView,其中签到按钮被添加到视图控制器的中心位置,签到记录的UITableView被添加到签到按钮的下方。 当用户点击签到按钮时,我们需要处理签到逻辑。我们可以在`checkInButtonClicked:`方法中完成这个逻辑。 至此,一个简单的签到APP的首页就完成了,您可以根据自己的需求对代码进行修改和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清风清晨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值