UIAlertController創(chuàng)建修改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.創(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;
}