0

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

rmaddy
  • 314,917
  • 42
  • 532
  • 579
marlabs
  • 21
  • 5

2 Answers2

1

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?

Community
  • 1
  • 1
Gurtej Singh
  • 3,244
  • 1
  • 14
  • 27
1

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];
Daniel Hariri
  • 1,081
  • 8
  • 10