UIButton with UITableViewCellSelectionStyleGray Selection Color

♀尐吖头ヾ 提交于 2019-12-04 03:42:31

问题


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


回答1:


Unfortunately I can't seem to find the actual color programmatically but DigitalColor Meter (OSX APP) says 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];



回答2:


Try this:

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



回答3:


When you set the tintColor property on a UIButton, the color is set on the highlighted state. So you could do this:

[button setTintColor:[UIColor lightGrayColor]];

However, lightGrayColor may not be the exact gray you're looking for. I'm not aware of a way to get reference to the exact selection-gray of a UITableViewCell. You might just have to play with [UIColor colorWithRed:green:blue:alpha:] to get it like you want it.

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



来源:https://stackoverflow.com/questions/18832184/uibutton-with-uitableviewcellselectionstylegray-selection-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!