我正在使用新的UIAlertController来显示警报.我有这个代码:
// nil titles break alert interface on iOS 8.0, so we'll be using empty strings
UIAlertController *alert = [UIAlertController alertControllerWithTitle: title == nil ? @"": title message: message preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle: cancelButtonTitle style: UIAlertActionStyleCancel handler: nil];
[alert addAction: defaultAction];
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootViewController presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
现在我想更改标题和消息字体,颜色,大小等.什么是最好的方法呢?
编辑: 我应该插入整个代码.我为UIView创建了一个类别,我可以为iOS版本显示正确的警报.
@implementation UIView (AlertCompatibility)
+( void )showSimpleAlertWithTitle:( NSString * )title
message:( NSString * )message
cancelButtonTitle:( NSString * )cancelButtonTitle
{
float iOSVersion = [[UIDevice currentDevice].systemVersion floatValue]; …Run Code Online (Sandbox Code Playgroud) 我一直在使用以下代码来更改我添加的项目的文本颜色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.
现在iOS8上的过时UIActionsheet和UIAlertview定制上iOS7工作不发生作用了.到目前为止,我所知道的唯一定制是色彩.我需要的是改变标题的字体大小和样式,我没有找到任何方式使用新的UIAlertAction.
已经提到了这个,但我仍然希望有一种方法可以至少改变标题大小和字体.
为您提供我的一些代码 UIAlertAction
UIAlertController * alertActionSheetController = [UIAlertController alertControllerWithTitle:@"Settings"
message:@""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * aboutTheAppAction = [UIAlertAction actionWithTitle:@"About the App"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
NSLog(@"About the app");
[self openAbout];
}];
[alertActionSheetController addAction:aboutTheAppAction];
[self presentViewController:alertActionSheetController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)