How to change color of UITableViewCell when selecting?

前端 未结 14 2530
予麋鹿
予麋鹿 2020-12-04 10:59

I have a menu like so:

\"Menu\"

The normal (unselected) state for each cell is an image, the selected s

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 11:44

    Using Objective C, Change Selected Cell Background color other than defaults. No need to create custom cells.

    If you only want to change the selected color of the cell, you can do this, Be aware that for this to work, in the Storyboard (or XIB file) you must select a Selected Background colour other than None. Just add following code in UITableView Delegate method : tableView cellForRowAtIndexPath:

    UIView *bgColor = [[UIView alloc] init];
    
    bgColor.backgroundColor = [UIColor yellowColor];
    
    [cell setSelectedBackgroundView:bgColor];
    

提交回复
热议问题