iOS开发UIAlertController之UIAlertAction加图片(UIAlertController按钮加图片)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ziyuzhiye/article/details/85261288

废话不多说,直接上代码

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"SWFT Blockchain" message:@"Enjoying SWFT Blockchain" preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"给一个超级牛逼的好评" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSString *urlStr = [NSString
                            stringWithFormat:@"https://itunes.apple.com/us/app/itunes-u/id%@?action=write-review&mt=8",
                            @"1435569339"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
        
    }]];
    
    //这里是重点
    UIAlertAction *secondAction = [UIAlertAction actionWithTitle:@" " style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSString *urlStr = [NSString
                            stringWithFormat:@"https://itunes.apple.com/us/app/itunes-u/id%@?action=write-review&mt=8",
                            @"1435569339"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
        
    }];
    UIImage *secondImage = [[UIImage imageNamed:@"grade_star"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [secondAction setValue:secondImage forKey:@"image"];

    [alert addAction:secondAction];
//    [alert addAction:[UIAlertAction actionWithTitle:attri style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"Remind me later" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }]];
    [self presentViewController:alert animated:true completion:^{
        
    }];

如图所示:

 

 

注:经过多次试验,提示框按钮上加的星星图片为250*22的一倍二倍三倍图。
 

T

展开阅读全文

没有更多推荐了,返回首页