国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 万州区| 凤庆县| 马鞍山市| 株洲县| 仁化县| 金塔县| 赤水市| 锦屏县| 虹口区| 汕尾市| 沂南县| 大埔县| 峡江县| 汝州市| 金塔县| 浑源县| 临夏市| 阿坝县| 临武县| 津市市| 内丘县| 深泽县| 老河口市| 洪洞县| 尉犁县| 宜章县| 石阡县| 恩施市| 门源| 浦城县| 固原市| 定边县| 工布江达县| 茂名市| 大冶市| 嘉善县| 东莞市| 柞水县| 错那县| 德令哈市| 乡城县|