顯示廣告
隱藏 ✕
Disp BBS guest 註冊 登入(i) 線上人數: 1
看板 Knuckles_note
作者 Knuckles (站長 那克斯)
標題 [Xcode] 修改 TableView 的顏色
時間 2014年09月02日 Tue. PM 10:59:58


在 storyboard 點選 Table View
在屬性設定的 View 設定 Background Color 為想要的顏色
[圖]
 

點選 Table View Cell
在屬性設定的 View 設定 Background 為 Clear Color
[圖]
 

但是很奇怪在 iOS7 的 storyboard
將 Table View Cell 的 Background 設為 Clear Color 無效
背景依然是白色,查了一下好像是bug
必需用程式設定才行


如果 Table View 是用 Dynamic Prototypes 的話

參考

在 -tableView:cellForRowAtIndexPath: 裡
取得 cell 後,加上

    [cell setBackgroundColor:[UIColor clearColor]];

 

如果 Table View 是用 Static Cells

參考

要新增自訂的 Class

將 -numberOfSectionsInTableView:
和 -tableView:numberOfRowsInSection:
這兩個方法刪掉

然後新增 -tableView:willDisplayCell:forRowAtIndexPath:
這個成員函數會在 cell 顯示前執行

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    [cell setBackgroundColor:[UIColor clearColor]];
}


如果是要用來顯示文字,不需要點選的 row
也可以設定 Table View Cell 裡的 Content View 的背景色即可
[圖]
 


修改選取時的背景色
參考

在 storyboard 只有提供 none, blue, gray 可以選
要用其他顏色的話可以在 -tableView:cellForRowAtIndexPath:
或 -tableView:willDisplayCell:forRowAtIndexPath:
裡加上

    UIView *bgColorView = [[UIView alloc] init];
    bgColorView.backgroundColor = [UIColor darkGrayColor];
    [cell setSelectedBackgroundView:bgColorView];


--
※ 作者: Knuckles 時間: 2014-09-02 22:59:58
※ 編輯: Knuckles 時間: 2014-09-26 00:34:46
※ 看板: KnucklesNote 文章推薦值: 0 目前人氣: 0 累積人氣: 1019 
分享網址: 複製 已複製
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇