marlabs
marlabs

Reputation: 21

Disable highlight button in uitableviewcell when select row

I have custom UITableViewCell and two buttons inside. When I select row, background for buttons change for the same color as background of selected row, and border for buttons disappears.

How Can I disable change border/background color for button when row is selected ?

Thanks for reply

Upvotes: 0

Views: 569

Answers (2)

Gurtej Singh
Gurtej Singh

Reputation: 3234

I achieved this using a clear background view for my cells and disabling selection color of the row, but I needed it that way. Don't know if it suits your need, but you can try this:

UIView *selectedView = [[UIView alloc] initWithFrame:cell.bounds];
selectedView.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = selectedView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;

Hope this helps.

Do checkout this thread as well : Why do all backgrounds disappear on UITableViewCell select?

Upvotes: 1

Daniel Hariri
Daniel Hariri

Reputation: 1121

1) Create a UIView and assign the desired background color. 2) Render the UIView to an UIImage 3) Set the backgroundImage of the button for the desired state.

UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
colorView.backgroundColor = color;

UIGraphicsBeginImageContext(colorView.bounds.size);
[colorView.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[button setBackgroundImage:colorImage forState: UIControlStateHighlighted];

Upvotes: 1

Related Questions