UIAlertController創(chuàng)建修改title與message字體和顏色以符合要求,且在子視圖(如cell)中展示alert;2018-03-09

UIAlertController創(chuàng)建修改title與message字體和顏色以符合要求,且在子視圖(如cell)中展示alert;

/**

? ? 變更佩戴的守護(hù)微章

*/

- (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.創(chuàng)建并添加按鈕

? ? 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;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容