UITableViewCell的選中時的顏色設置

  1. 1.系統默認的顏色設置  
  1. //無色  
  2. cell.selectionStyle = UITableViewCellSelectionStyleNone;  
  3.   
  4. //藍色  
  5. cell.selectionStyle = UITableViewCellSelectionStyleBlue;  
  6.   
  7. //灰色  
  8. cell.selectionStyle = UITableViewCellSelectionStyleGray;  


2.自定義顏色和背景設置

 改變UITableViewCell選中時背景色:

UIColor *color = [[UIColoralloc]initWithRed:0.0green:0.0blue:0.0alpha:1];//通過RGB來定義自己的顏色

[html] view plaincopy
  1. cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];  
  2. cell.selectedBackgroundView.backgroundColor = [UIColor xxxxxx];  

3自定義UITableViewCell選中時背景

[html] view plaincopy
  1. cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellart.png"]] autorelease];   
  2. 還有字體顏色   
  3. cell.textLabel.highlightedTextColor = [UIColor xxxcolor];  [cell.textLabel setTextColor:color];//設置cell的字體的顏色  

4.設置tableViewCell間的分割線的顏色


[theTableView setSeparatorColor:[UIColor xxxx ]];


5、設置cell中字體的顏色

<span class="com" style="color: rgb(136, 136, 136);">// Customize the appearance of table view cells.</span><span class="pln" style="color: rgb(0, 0, 0);">
</span><span class="pun" style="color: rgb(0, 0, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(0, 0, 0);">(</span><span class="typ" style="color: rgb(0, 0, 136);">UITableViewCell</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(0, 0, 0);">*)</span><span class="pln" style="color: rgb(0, 0, 0);">tableView</span><span class="pun" style="color: rgb(0, 0, 0);">:(</span><span class="typ" style="color: rgb(0, 0, 136);">UITableView</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(0, 0, 0);">*)</span><span class="pln" style="color: rgb(0, 0, 0);">tableView cellForRowAtIndexPath</span><span class="pun" style="color: rgb(0, 0, 0);">:(</span><span class="typ" style="color: rgb(0, 0, 136);">NSIndexPath</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(0, 0, 0);">*)</span><span class="pln" style="color: rgb(0, 0, 0);">indexPath
</span><span class="pun" style="color: rgb(0, 0, 0);">{</span><span class="pln" style="color: rgb(0, 0, 0);">
  </span><span class="kwd" style="color: rgb(136, 0, 0);">if</span><span class="pun" style="color: rgb(0, 0, 0);">(</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(0, 0, 0);">==</span><span class="pln" style="color: rgb(0, 0, 0);"> indexPath</span><span class="pun" style="color: rgb(0, 0, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">row</span><span class="pun" style="color: rgb(0, 0, 0);">)</span><span class="pln" style="color: rgb(0, 0, 0);">
  </span><span class="pun" style="color: rgb(0, 0, 0);">{</span><span class="pln" style="color: rgb(0, 0, 0);">
    cell</span><span class="pun" style="color: rgb(0, 0, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">textLabel</span><span class="pun" style="color: rgb(0, 0, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">textColor </span><span class="pun" style="color: rgb(0, 0, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(0, 0, 0);">...;</span><span class="pln" style="color: rgb(0, 0, 0);">
    cell</span><span class="pun" style="color: rgb(0, 0, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">textLabel</span><span class="pun" style="color: rgb(0, 0, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">highlightedTextColor </span><span class="pun" style="color: rgb(0, 0, 0);">=</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(0, 0, 0);">...;</span><span class="pln" style="color: rgb(0, 0, 0);">
  </span><span class="pun" style="color: rgb(0, 0, 0);">}</span><span class="pln" style="color: rgb(0, 0, 0);">
  </span><span class="pun" style="color: rgb(0, 0, 0);">...</span><span class="pln" style="color: rgb(0, 0, 0);">
</span><span class="pun" style="color: rgb(0, 0, 0);">}</span>
發佈了17 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章