UIAlertController创建修改title与message字体和颜色以符合要求,且在子视图(如cell)中展示alert;2018-03-09

UIAlertController创建修改title与message字体和颜色以符合要求,且在子视图(如cell)中展示alert;

/**

    变更佩戴的守护微章

*/

- (void)changeGuardianMicoSeal{

    //    //修改title

    //    NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"物品详情"];

    //    [alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];

    //    [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];

    //    [alertController setValue:alertControllerStr forKey:@"attributedTitle"];

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确定佩戴展示我是牛泡泡的初级微章么" preferredStyle:UIAlertControllerStyleAlert];

    // 2.创建并添加按钮

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        NSLog(@"OK Action");

    }];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

        NSLog(@"Cancel Action");

    }];

    [alertController addAction:okAction]; // A

    [alertController addAction:cancelAction]; // B

    NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"确定佩戴展示我是牛泡泡的初级微章么"];

    [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6, 5)];

    [alertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];

    [[self topViewController] presentViewController:alertController animated:YES completion:nil];

}

- (UIViewController *)topViewController {

    UIViewController *resultVC;

    resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];

    while (resultVC.presentedViewController) {

        resultVC = [self _topViewController:resultVC.presentedViewController];

    }

    return resultVC;

}

- (UIViewController *)_topViewController:(UIViewController *)vc {

    if ([vc isKindOfClass:[UINavigationController class]]) {

        return [self _topViewController:[(UINavigationController *)vc topViewController]];

    } else if ([vc isKindOfClass:[UITabBarController class]]) {

        return [self _topViewController:[(UITabBarController *)vc selectedViewController]];

    } else {

        return vc;

    }

    return nil;

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容