日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS - UITableViewCell的选中时的颜色及tableViewCell的selecte与deselecte

發(fā)布時間:2025/7/14 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS - UITableViewCell的选中时的颜色及tableViewCell的selecte与deselecte 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

  • 1.系統(tǒng)默認的顏色設置??
  • [cpp]?view plaincopy
  • //無色??
  • cell.selectionStyle?=?UITableViewCellSelectionStyleNone;??
  • ??
  • //藍色??
  • cell.selectionStyle?=?UITableViewCellSelectionStyleBlue;??
  • ??
  • //灰色??
  • cell.selectionStyle?=?UITableViewCellSelectionStyleGray;??
  • ?

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

    ?改變UITableViewCell選中時背景色:

    ?

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

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

    ?

    3自定義UITableViewCell選中時背景

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

    ?

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


    [theTableView setSeparatorColor:[UIColor xxxx ]];

    4.pop返回table時,cell自動取消選中狀態(tài)

    首先我有一個UITableViewController,其中每個UITableViewCell點擊后都會push另一個ViewController,每次點擊Cell的時候,Cell都會被選中,當從push的ViewController返回的時候選中的Cell便會自動取消選中。后來由于某些原因我把這個UITableViewController改成了UIViewController,之后就產生了一個問題:每次返回到TableView的時候,之前選中的Cell不能自動取消選中,經(jīng)過查找得知:

    UITableViewController有一個clearsSelectionOnViewWillAppear的property,

    而當把UITableViewController修改成UIViewController后,這個屬性自然就不存在了,因此我們必須手動添加取消選中的功能,方法很簡單,在viewWillAppear方法中加入:

    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];

    ?

    ?

    6.點擊后,過段時間cell自動取消選中

    ?- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    ?????…………

    ????//消除cell選擇痕跡

    ????[self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];

    }

    - (void)deselect

    {

    ????[self.tableview deselectRowAtIndexPath:[self.tableview indexPathForSelectedRow] animated:YES];

    }

    轉載于:https://www.cnblogs.com/mcj-coding/p/3606897.html

    總結

    以上是生活随笔為你收集整理的IOS - UITableViewCell的选中时的颜色及tableViewCell的selecte与deselecte的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。