UITableViewCell Selectioncolor hides everything
When I select a custom made cell it hides everything in the cell and sho开发者_StackOverflow社区ws only the selection color.
how can I just darken the background a bit when selected?
Alternatively to overriding setHighlighted:
, you can use the view makeup of a table view cell to your advantage.
When iOS applies the highlight, it is actually using the selectedBackgroundView
property of each table view cell. So, you can make a custom UIView (style it however, such as giving it your desired background colour) and set that as the selectedBackgroundView
property (cell.selectedBackgroundView
) of the table view cell. Do this in cellForRowAtIndexPath:
, when customising the other details of your cell.
This will mean you take control of the selection yourself; the iOS default gradient will not be applied.
It is also possible to change the selectedBackgroundView
via Interface Builder. In the same nib as your custom cell, create another view in the nib - not a subview of the custom table view cell - and wire that up with the `selectedBackgroundView' outlet of the custom table view cell.
If that's a custom cell, implement
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
And adjust the background color within it.
You can just add highlighted text color when you select cell.
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"part2.png"]];
cell.textLabel.highlightedTextColor = [UIColor blackColor];
Set selected Text Color as per your highlighted cell selection color.
精彩评论