UITableViewCell在編輯狀態(tài)下背景顏色的修改方法
本文主要介紹的是關(guān)于UITableViewCell在編輯狀態(tài)下背景顏色的修改方法,分享出來供大家參考學(xué)習(xí),下面來一起看看詳細的介紹:
一、先看下效果圖
二、網(wǎng)上很多下面這種答案
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath]; cell.selectionStyle = UITableViewCellSelectionStyleNone;
這樣設(shè)置,藍色的選中圖標(biāo)也不會出現(xiàn).
這種僅限于不編輯的時候,讓TableViewCell沒有灰色高亮.
三、具體實現(xiàn):
(1).在創(chuàng)建cell的時候設(shè)置selectedBackgroundView
RealTimeControlTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (cell == nil) { cell = [[RealTimeControlTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId]; cell.contentView.backgroundColor = [UIColor clearColor]; UIView *backGroundView = [[UIView alloc]init]; backGroundView.backgroundColor = [UIColor clearColor]; cell.selectedBackgroundView = backGroundView; }
(2).自定義一個UITableVIewCell重寫
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { if (!self.editing) { return; } [super setSelected:selected animated:animated]; if (self.editing) { self.contentView.backgroundColor = [UIColor clearColor]; self.textLabel.backgroundColor = [UIColor clearColor]; self.detailTextLabel.backgroundColor = [UIColor clearColor]; } }
(3)還要重寫下面方法 因為在長按cell的時候也會高亮,出現(xiàn)灰色的背景
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{ return; }
對上面第二步代碼說明:
1.在非編輯狀態(tài)下,默認不會出現(xiàn)選中效果,直接return.
return 以后還是會繼續(xù)調(diào)用
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 在這里處理cell的點擊事件 }
2.要實現(xiàn)選中的藍色圖標(biāo)出現(xiàn),以及添加cell到選中cell的數(shù)組.
調(diào)用系統(tǒng)的默認方法
[super setSelected:selected animated:animated];
3.在編輯狀態(tài)下修改cell的contenView為clear,清除選中時候的灰色背景.
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
- IOS UITableView和UITableViewCell的幾種樣式詳細介紹
- IOS UITableViewCell詳解及按鈕點擊事件處理實例
- 全面解析iOS應(yīng)用中自定義UITableViewCell的方法
- 詳解ios中自定義cell,自定義UITableViewCell
- iOS App開發(fā)中使用及自定義UITableViewCell的教程
- 詳解IOS UITableViewCell 的 imageView大小更改
- 詳解iOS tableViewCell自適應(yīng)高度 第三發(fā)類庫
- iOS中使用UItableviewcell實現(xiàn)團購和微博界面的示例
- iOS優(yōu)化UITableViewCell高度計算的一些事兒
- 你應(yīng)該知道的tableViewCell行高計算處理
相關(guān)文章
iOS中滑動控制屏幕亮度和系統(tǒng)音量(附加AVAudioPlayer基本用法和Masonry簡單使用)
這篇文章主要介紹了iOS中滑動控制屏幕亮度和系統(tǒng)音量(附加AVAudioPlayer基本用法和Masonry簡單使用)的相關(guān)資料,需要的朋友可以參考下2016-12-12