Change UIActionSheet buttons background color and button font

允我心安 提交于 2020-01-06 19:29:06

问题


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 UICollectionViews elsewhere in your app, set the background color manually to override.



来源:https://stackoverflow.com/questions/30287400/change-uiactionsheet-buttons-background-color-and-button-font

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