UITableView(四)幾種常用設置

  • 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];
    
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容