国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

UITableViewCell在編輯狀態(tài)下背景顏色的修改方法

2020-07-26 02:46:21
字體:
供稿:網(wǎng)友

本文主要介紹的是關(guān)于UITableViewCell在編輯狀態(tài)下背景顏色的修改方法,分享出來供大家參考學(xué)習(xí),下面來一起看看詳細的介紹:

一、先看下效果圖


二、網(wǎng)上很多下面這種答案

UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];cell.selectionStyle = UITableViewCellSelectionStyleNone;

這樣設(shè)置,藍色的選中圖標也不會出現(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)選中的藍色圖標出現(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í)或者工作能帶來一定的幫助,如有疑問大家可以留言交流,謝謝大家對武林網(wǎng)的支持。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 望都县| 阳山县| 隆安县| 高唐县| 临潭县| 专栏| 油尖旺区| 泸水县| 寻乌县| 乐业县| 包头市| 邹城市| 武宣县| 遂昌县| 台前县| 林甸县| 观塘区| 茂名市| 吕梁市| 遵义县| 吴川市| 四平市| 弥渡县| 乌审旗| 乌海市| 康乐县| 雷波县| 广德县| 遂平县| 济宁市| 临沭县| 屯门区| 夏邑县| 西吉县| 思南县| 吴旗县| 正蓝旗| 翼城县| 通山县| 边坝县| 宜良县|