问题
I have a UIActionSheet in my application. I want to change the background color of actionsheet buttons and the font of the buttons. I made a search found below code:
for (UIView *_currentView in actionSheet.subviews)
{
if ([_currentView isKindOfClass:[UIButton class]])
{
//DO YOUR WORK
}
}
but this code is not working on ios 8. for ios I found below code too:
[[UIView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor redColor]];
but this code only changes the button's font color.
Is there a way for changing the button's background color too?
回答1:
Basically what you are trying to do is something you should not do and should never have been doing. UIActionSheet and UIAlertController provide standard views with a very small number of variants and a completely standard appearance. You should not attempt to mess with that.
However, don't give up hope! Nothing stops you from devising your own view that looks however you want. And on iOS 8 (and iOS 7) this is very easy, because you are allowed to make a presented view controller whose view slides onto the screen and covers it only partially, just like an alert sheet. So go ahead and create your own non-standard column of buttons, rather than trying to modify Apple's standard.
回答2:
What works for me is this:
UICollectionViewCell.appearance().backgroundColor = UIColor.whiteColor() // or any other color you want
Note that this affects the background when presented in a popover or on the iPhone. If you are using UICollectionView
s elsewhere in your app, set the background color manually to override.
来源:https://stackoverflow.com/questions/30287400/change-uiactionsheet-buttons-background-color-and-button-font