UIButton with select color UITableViewCellSelectionStyleGray

I am trying to set the selected color for UIButton to the color "UITableViewCellSelectionStyleGray"; The problem is that the UIButton highlight color cannot be set, but only the image. Does anyone know how to make an image that is the exact color of a selected cell using a UITableViewCellSelectionStyleGray?

+4
source share
3 answers

Unfortunately, I cannot find the actual color programmatically, but the DigitalColor Meter (OSX APP) says that the color is 217 217 217

 UIColor* selectedColor = [UIColor colorWithRed:217.0/255.0 green:217.0/255.0 blue:217.0/255.0 alpha:1.0]; 
+3
source

Try the following:

 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(50, 50, 60, 20); button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"orange.jpg"]]; [self.view addSubview:button]; 
+1
source

When you set the tintColor property to UIButton , the color is set in the selected state. So you can do this:

 [button setTintColor:[UIColor lightGrayColor]]; 

However, lightGrayColor may not be the exact gray color you are looking for. I do not know how to get a link to the exact selection series of UITableViewCell . You just need to play with [UIColor colorWithRed:green:blue:alpha:] to get it the way you want it.

** Also not that the tintColor property has different effects in iOS 7, so beware of this if you use this code.

0
source

Source: https://habr.com/ru/post/1208354/


All Articles