美文网首页程序员iOS开发iOS进阶指南
UITableView(四)几种常用设置

UITableView(四)几种常用设置

作者: 飞翔的道长 | 来源:发表于2016-04-24 23:39 被阅读270次
  • UITableView的常见设置

    • 设置分割线颜色
    self.tableView.separatorColor = [UIColor redColor];
    
    • 隐藏分割线,在需要自定义分割线时可以先更改该属性,然后再添加想要的分割线样式,用AutoLayout设置在每行的底部即可
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
  • UITableViewCell的常见设置

    • 取消选中的样式,在单纯的展示数据时可用
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    • 设置选中的背景色
      UIView *selectedBackgroundView = [[UIView alloc] init];
      selectedBackgroundView.backgroundColor = [UIColor redColor];
      cell.selectedBackgroundView = selectedBackgroundView;
    
    • 设置默认的背景色,两种方法,需要注意的是backgroundView的优先级 大于 backgroundColor
      UIView *selectedBackgroundView = [[UIView alloc] init];
      selectedBackgroundView.backgroundColor = [UIColor redColor];
      cell.selectedBackgroundView = selectedBackgroundView;
    
       cell.backgroundColor = [UIColor blueColor];
    
    • 设置指示器

      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      
  • 最右侧添加控件

    cell.accessoryView = [[UISwitch alloc] init];
    

相关文章

网友评论

    本文标题:UITableView(四)几种常用设置

    本文链接:https://www.haomeiwen.com/subject/cpifrttx.html