Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView: selected cell color is not rendered in ios13

Tags:

ios13

I'm using Xcode 11 beta 6, on selecting the UITableViewcell ,cell has not been highlighted.It has a white background instead of showing selected background color.

like image 454
Haritha Reddy Avatar asked Aug 28 '19 18:08

Haritha Reddy


2 Answers

Per iOS 13 release notes (https://developer.apple.com/documentation/ios_ipados_release_notes/ios_ipados_13_beta_8_release_notes) - The UITableViewCell class no longer changes the backgroundColor or isOpaque properties of the contentView and any of its subviews when cells become highlighted or selected.

The UITableViewCell class no longer changes the backgroundColor or isOpaque properties of the contentView and any of its subviews when cells become highlighted or selected. If you are setting an opaque backgroundColor on any subviews of the cell inside (and including) the contentView, the appearance when the cell becomes highlighted or selected might be affected. The simplest way to resolve any issues with your subviews is to ensure their backgroundColor is set to nil or clear, and their opaque property is false. However, if needed you can override the setHighlighted(:animated:) and setSelected(:animated:) methods to manually change these properties on your subviews when moving to or from the highlighted and selected states.

like image 160
nambatee Avatar answered Nov 18 '22 02:11

nambatee


This works for me for iOS13 device that build with Xcode11.1

Objective-c

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

   cell.contentView.backgroundColor = [UIColor clearColor];

}

Swift

cell.contentView.backgroundColor = UIColor.clearColor()
like image 3
Roger Han Avatar answered Nov 18 '22 01:11

Roger Han