How to Change the Blue Highlight Color of a Uitableviewcell

How to change the blue highlight color of a UITableViewCell?

You can change the highlight color in several ways.

  1. Change the selectionStyle property of your cell. If you change it to UITableViewCellSelectionStyleGray, it will be gray.

  2. Change the selectedBackgroundView property. Actually what creates the blue gradient is a view. You can create a view and draw what ever you like, and use the view as the background of your table view cells.

How to change blue highlight color when a cell is selected

inside tableview's

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Create a uiimageview and change it's background color to your desired color

if (cell == nil) {
UIImageView *bgView = [[UIImageView alloc]initWithFrame:cell.frame];
bgView.backgroundColor = [UIColor greenColor];
cell.selectedBackgroundView = bgView;
}

Cannot change UITableView blue highlight color

Implement it as follows:-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath {

[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
}

OR

Set the selectedBackgroundView's color as what you want in your custom tableview cell (which is a subclass of UITableViewCell):

UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
[selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here
[self setSelectedBackgroundView:selectedBackgroundView];

or you can configure it in -tableView:cellForRowAtIndexPath: method:

//...
[cell setSelectedBackgroundView:selectedBackgroundView];
//...

UITableView Cell selected Color?

I think you were on the right track, but according to the class definition for selectedBackgroundView:

The default is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for section-group tables UITableViewStyleGrouped).

Therefore, if you're using a plain-style table, then you'll need to alloc-init a new UIView having your desired background colour and then assign it to selectedBackgroundView.

Alternatively, you could use:

cell.selectionStyle = UITableViewCellSelectionStyleGray;

if all you wanted was a gray background when the cell is selected. Hope this helps.

Remove the cell highlight color of UITableView

In Swift:

cell.selectionStyle = UITableViewCell.SelectionStyle.none

or simply:

cell.selectionStyle = .none

How to change color of UITableViewCell when selecting?

iOS 6.0 and later

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
// Add your Colour.
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
[self setCellColor:[UIColor whiteColor] ForCell:cell]; //highlight colour
}

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
// Reset Colour.
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
[self setCellColor:[UIColor colorWithWhite:0.961 alpha:1.000] ForCell:cell]; //normal color

}

- (void)setCellColor:(UIColor *)color ForCell:(UITableViewCell *)cell {
cell.contentView.backgroundColor = color;
cell.backgroundColor = color;
}

Custom UITableViewCell

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];

UIView * selectedBackgroundView = [[UIView alloc] init];
[selectedBackgroundView setBackgroundColor:[UIColor colorFromHexString:@"5E6073"]]; // set color here
[self setSelectedBackgroundView:selectedBackgroundView];
}

iOS 7 change UITableViewCell font color to blue like in Settings app

If you're using a storyboard or xib and you have a prototype cell, go in to it and select the label. Then you can set the color of the text.

If you want to do it programmatically, add the following to your tableView:cellForRowAtIndexPath: method:

cell.textLabel.textColor = [UIColor blueColor];

blueColor isn't exactly the same as the blue used by buttons in iOS 7, but you could manually pick a color that closely approximates it if you wanted instead.

EDIT:

This will give you the exact color you want:

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
cell.textLabel.textColor = [button titleColorForState:UIControlStateNormal];

It's getting the color from a UIButton.

TableView, how change the cell default blue color

in

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

method add this code

    cell.selectionStyle = UITableViewCellSelectionStyleNone;


Related Topics



Leave a reply



Submit