UIAlertController 自定義

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"標題" message:@"內(nèi)容" preferredStyle:UIAlertControllerStyleAlert];
    
    // 使用富文本來改變alert的title字體大小和顏色
    NSMutableAttributedString *titleText = [[NSMutableAttributedString alloc] initWithString:@"這里是標題"];
    [titleText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:24] range:NSMakeRange(0, 2)];
    [titleText addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
    [alert setValue:titleText forKey:@"attributedTitle"];
    
    // 使用富文本來改變alert的message字體大小和顏色
    // NSMakeRange(0, 2) 代表:從0位置開始 兩個字符
    NSMutableAttributedString *messageText = [[NSMutableAttributedString alloc] initWithString:@"這里是正文信息"];
    [messageText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:10] range:NSMakeRange(0, 6)];
    [messageText addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
    [messageText addAttribute:NSForegroundColorAttributeName value:[UIColor brownColor] range:NSMakeRange(3, 3)];
    [alert setValue:messageText forKey:@"attributedMessage"];


    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    // 設(shè)置按鈕背景圖片
    UIImage *accessoryImage = [[UIImage imageNamed:@"selectRDImag.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [cancelAction setValue:accessoryImage forKey:@"image"];
    
    // 設(shè)置按鈕的title顏色
    [cancelAction setValue:[UIColor lightGrayColor] forKey:@"titleTextColor"];
    
    // 設(shè)置按鈕的title的對齊方式
    [cancelAction setValue:[NSNumber numberWithInteger:NSTextAlignmentLeft] forKey:@"titleTextAlignment"];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"確認" style:UIAlertActionStyleDefault handler:nil];

    [alert addAction:okAction];
    [alert addAction:cancelAction];

    [self presentViewController:alert animated:YES completion:nil];
    
效果圖.png
UIAlertController 私有 api 列表及其類型:
_message, @"NSString"
_attributedTitle, @"NSAttributedString"
_attributedMessage, @"NSAttributedString"
_attributedDetailMessage, @"NSAttributedString"
_linkedAlertControllers, @"NSSet"
_cancelAction, @"UIAlertAction"
_actionToKeyCommandsDictionary, 
_keyCommandToActionMapTable, @"NSMapTable"
_resolvedStyle, q
_preferredStyle, q
_contentViewController, @"UIViewController"
_textFieldViewController, 
_backButtonDismissGestureRecognizer, 
_ownedTransitioningDelegate, @
_addContentViewControllerToViewHierarchyNeeded, B
_isInSupportedInterfaceOrientations, B
_isInRecomputePreferredContentSize, B
_batchActionChangesInProgressCount, q
_presenter, @"_UIAlertControllerShimPresenter"
_actionsWithInvokedHandlers, @"NSPointerArray"
_alertControllerStackManager, 
_hidden, B
_springLoaded, B
__shouldFlipFrameForShimDismissal, B
__shouldAllowNilParameters, B
_hasPreservedInputViews, B
_actions, @"NSMutableArray"
_headerContentViewController, @"UIViewController"
_separatedHeaderContentViewController, 
_styleProvider, 
_preferredAction, @"UIAlertAction"
_temporaryAnimationCoordinator, 
_previewInteractionController, 
__visualStyle, @"UIAlertControllerVisualStyle"
_indexesOfActionSectionSeparators, @"NSIndexSet"
__actionDelimiterIndices, @"NSMutableArray"
__compatibilityPopoverController, 
__systemProvidedPresentationView, @"UIView"
__systemProvidedPresentationDelegate, 
_systemProvidedGestureRecognizer, 
_coordinatedActionPerformingDelegate, 
__presentationSourceRepresentationView, @"UIView"
_titleMaximumLineCount, q
_titleLineBreakMode, q
UIAlertAction 私有 api 列表及其類型:
_title, @"NSString"
_titleTextAlignment, q
_enabled, B
_checked, B
_isPreferred, B
_imageTintColor, @"UIColor"
_titleTextColor, @"UIColor"
_style, q
_handler, @?
_simpleHandler, @?
_image, @"UIImage"
_shouldDismissHandler, @?
__descriptiveText, @"NSString"
_contentViewController, @"UIViewController"
_keyCommandInput, @"NSString"
_keyCommandModifierFlags, q
__representer, 
__interfaceActionRepresentation, @"UIInterfaceAction<UIAlertActionMutablePropertyObservering>"
__alertController, @"UIAlertController"

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末店量,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子愕难,更是在濱河造成了極大的恐慌撒强,老刑警劉巖锌雀,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蹂随,死亡現(xiàn)場離奇詭異琉预,居然都是意外死亡劝评,警方通過查閱死者的電腦和手機姐直,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蒋畜,“玉大人声畏,你說我怎么就攤上這事∫龀桑” “怎么了插龄?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長科展。 經(jīng)常有香客問我均牢,道長,這世上最難降的妖魔是什么才睹? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任徘跪,我火速辦了婚禮,結(jié)果婚禮上琅攘,老公的妹妹穿的比我還像新娘垮庐。我一直安慰自己,他們只是感情好坞琴,可當我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布哨查。 她就那樣靜靜地躺著,像睡著了一般剧辐。 火紅的嫁衣襯著肌膚如雪寒亥。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天浙于,我揣著相機與錄音护盈,去河邊找鬼。 笑死羞酗,一個胖子當著我的面吹牛腐宋,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播檀轨,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼胸竞,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了参萄?” 一聲冷哼從身側(cè)響起卫枝,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎讹挎,沒想到半個月后校赤,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體吆玖,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年马篮,在試婚紗的時候發(fā)現(xiàn)自己被綠了沾乘。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡浑测,死狀恐怖翅阵,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情迁央,我是刑警寧澤掷匠,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站岖圈,受9級特大地震影響讹语,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜蜂科,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一募强、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧崇摄,春花似錦、人聲如沸慌烧。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽屹蚊。三九已至厕氨,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間汹粤,已是汗流浹背命斧。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留嘱兼,地道東北人国葬。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像芹壕,于是被迫代替她去往敵國和親汇四。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,779評論 2 354