uialertcontroller ios

时间:2016-01-19 13:21:16

标签: ios objective-c button uialertcontroller

有没有办法自定义buttons的{​​{1}}?我已经看到如何自定义字体,大小和颜色,但无法添加uialertcontroller按钮的背景图像或颜色。

uialertcontroller

请建议是否有办法设置按钮的背景图像。

2 个答案:

答案 0 :(得分:0)

您可以添加附件图像:

UIAlertAction *selectImage = [UIAlertAction
                            actionWithTitle:@"First Button"
                            style:UIAlertActionStyleDefault
                            handler:^(UIAlertAction *action){

                                NSLog(@"First Button");

                            }];

[alertController addAction:selectImage];

UIImage *image = [UIImage imageNamed:@"Image.jpg"];
[selectImage setValue:image forKey:@"image"];

此外,如上所述,您可以创建自定义视图并覆盖touchesEnded。

答案 1 :(得分:0)

尝试以下编码,对您有所帮助。

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Dont care what goes here, since we're about to change below" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"Presenting the great... Hulk Hogan!"];
[hogan addAttribute:NSFontAttributeName
              value:[UIFont systemFontOfSize:50.0]
              range:NSMakeRange(24, 11)];
[alertVC setValue:hogan forKey:@"attributedTitle"];



UIAlertAction *button = [UIAlertAction actionWithTitle:@"Label text"
                                                 style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction *action){
                                                   //add code to make something happen once tapped
                                               }];
UIImage *accessoryImage = [UIImage imageNamed:@"addusergroup.png"];
[button setValue:accessoryImage forKey:@"image"];
[self presentViewController:alertVC animated:YES completion:nil];