tableViewCell - 常见设置

UITableViewCell的常见设置

  • 分割线颜色
    • 分割线颜色,系统自带的分割线两边是不到屏幕边缘,当边缘有图片时更加明显,达不到所要的要求
    • 解决:可以将系统的分割线隐藏,自定义一个view,位置紧贴cell底部,设置为亮灰色,高度为1,如果太粗可以设置提高透明度
    //self.tableView.separatorColor = [UIColor redColor];

    // 隐藏分割线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  • 常用几个属性
    • selectionStyle:选中样式(颜色),系统只有灰色和无,要想使用其他颜色或者显示图片等效果可以通过cell.selectedBackgroundView属性设置.
    • selectedBackgroundView:设置选中后的背景效果,以为内继承自view,可以设置颜色,图片,其他控件等
    • backgroundColor:默认背景色
    • backgroundView:设置背景效果,继承自view,可以自定义颜色,图片等.
      • 等级比 backgroundColor高,比如分别通过backgroundView和backgroundColor设置背景色,只会显示backgroundView设置的背景色.
    // 取消选中的样式
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //cell.selectionStyle = UITableViewCellSelectionStyleGray;

    // 设置选中的背景色
    UIView *selectedBackgroundView = [[UIView alloc] init];
    selectedBackgroundView.backgroundColor = [UIColor redColor];
    cell.selectedBackgroundView = selectedBackgroundView;

    // 设置默认的背景色
    cell.backgroundColor = [UIColor blueColor];

    // 设置默认的背景色
    UIView *backgroundView = [[UIView alloc] init];
    backgroundView.backgroundColor = [UIColor greenColor];
    cell.backgroundView = backgroundView;
  • 设置指示器
    • accessoryType:位置在cell的右侧
    • UITableViewCellAccessoryDisclosureIndicator
      这里写图片描述
    • UITableViewCellAccessoryDetailDisclosureButton
      这里写图片描述
    • UITableViewCellAccessoryCheckmark
      这里写图片描述
    • UITableViewCellAccessoryDetailButton
      这里写图片描述
    • UITableViewCellAccessoryNone
    // 设置指示器
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //cell.accessoryView = [[UISwitch alloc] init];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值