问题描述
我的应用程序中有一个UIActionSheet。我想更改操作表按钮的背景颜色和按钮的字体。我在下面的代码中找到了一个搜索:
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
}
}
但此代码不适用于ios 8.对于ios我也在以下代码中找到:
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?
推荐答案
基本上你要做的是什么你不应该做,也不应该做。 UIActionSheet和UIAlertController提供具有极少数变体和完全标准外观的标准视图。你不应该试图弄乱它。
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.
然而,不要放弃希望!没有什么可以阻止你设计你想要的自己的视图。在iOS 8(和iOS 7)上,这非常简单,因为您可以制作一个呈现的视图控制器,其视图滑动到屏幕上并仅部分覆盖它,就像警报表一样。因此,请继续创建您自己的非标准按钮列,而不是尝试修改Apple的标准。
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.
这篇关于更改UIActionSheet按钮背景颜色和按钮字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!