iOS 8之前貌似可以遍歷UIAlertView的子視圖來(lái)更改. 現(xiàn)在是gg了. 以下是傻瓜式教學(xué).
步驟一: 使用KVC用一個(gè)Label替代需要顯示的帶字的view. 在這個(gè)Label里, 就可以自己隨便設(shè)置字體顏色和大小. 下面的代碼不用仔細(xì)看了 直接復(fù)制粘貼走不謝.
步驟二: 步驟一有一個(gè)問(wèn)題是, 顯示的UIAlertView上面的字沒有內(nèi)邊距(字都頂?shù)竭吷狭?看起來(lái)特別山寨). 然而你想設(shè)置Label的內(nèi)邊距是沒門的因?yàn)長(zhǎng)abel本來(lái)就沒有內(nèi)邊距這個(gè)屬性. 所以我們可以自定義一個(gè)帶頁(yè)邊距的Label. 步驟一里的label繼承這個(gè)label就自動(dòng)有內(nèi)邊距了. 想要這個(gè)label的源碼請(qǐng)戳這里http://www.reibang.com/p/d8d29e30d2d4(感謝作者).
UIAlertView * alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
[alertView addButtonWithTitle:@"取消"];
[alertView addButtonWithTitle:@"去修改"];
SFLabel *textLabel = [[SFLabel alloc] init];
textLabel.font = [UIFont systemFontOfSize:13];
textLabel.textColor = [UIColor blackColor];
textLabel.backgroundColor = [UIColor clearColor];
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;
textLabel.textAlignment = NSTextAlignmentCenter;
textLabel.text = @"你好我是豆芽爹, 以及樹人groot的腦殘粉";
[alertView setValue:textLabel forKey:@"accessoryView"];
[alertView show];