我一直在使用以下代码来更改我添加的项目的文本颜色UIActionSheet.:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
}
}
Run Code Online (Sandbox Code Playgroud)
它工作正常iOS7,但在iOS8上面的代码中不会更改项目的文本颜色.
现在的问题是如何改变我在新增项目的文本颜色UIActionSheet使用iOS8?
附加信息:
我添加了断点,以查看上述代码中的以下行是否被执行:
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
这些行不会被执行.所以,if([subview isKindOfClass:[UIButton class]])总是false适用于所有项目actionSheet.subviews.所以我认为观点层次
UIActionSheet改变了.
如何编辑UIAlertAction文字大小和颜色?我已经采取了UIAlertController如何编辑大小的方法.这个我smy代码
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Do you wish to logout?" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *logOut = [UIAlertAction actionWithTitle:@"Log Out" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}];
Run Code Online (Sandbox Code Playgroud)
现在我想要我的'Log Out'文本,字体大小为22,绿色和semibold.
如何更改UIAlertAction已添加到按钮的按钮的颜色UIAlertController?
此处已经回答了更改 UIAlertViewController对象的消息和标题的字体:如何在UIAlertController中更改UIAlertAction的字体大小和颜色.
但我想知道如何使用Swift更改UIAlertAction(iOS8 +)标题上的字体.不幸的是,UIAlertAction实例没有一个名为"attributionTitle"的属性,就像UIAlertController一样.
我要扩展以更改字体的代码如下:
let alertAction = UIAlertAction(title: "Got It!", style: .Default, handler: nil)
alertController.addAction(alertAction)
Run Code Online (Sandbox Code Playgroud)
任何想法将不胜感激.
https://www.safaribooksonline.com/library/view/ios-8-swift/9781491908969/images/ispc_0113.png
在上图中如何更改"完成","其他动作"的字体大小和颜色?以及如何更改"标题"和"消息"的字体大小和颜色?
谢谢.