我們用的UIAlertView和UIAlertController中標(biāo)題title和顯示信息message的格式都是有默認(rèn)值得,特別是message是我們比較常用的,它的模式對(duì)齊格式是居中對(duì)齊,對(duì)于一般的需求是可以滿足的,但是如果對(duì)于我們顯示版本更新內(nèi)容這樣的要求時(shí),居中對(duì)齊就略顯粗狂了,左對(duì)齊才是我們想要的。現(xiàn)以UIAlertController為例,下面是詳細(xì)代碼。
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"新版本:V-1.2" message:@"更新內(nèi)容" ?preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"暫不更新" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"去下載" style:UIAlertActionStyleDefault handler:^(UIAlertAction *act){
NSLog(@"you press ok button");
// [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"下載地址"]];
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
//下面的代碼就是找出標(biāo)題和消息內(nèi)容的承載標(biāo)簽控件
UIView *subView1 = alertController.view.subviews[0];
UIView *subView2 = subView1.subviews[0];
UIView *subView3 = subView2.subviews[0];
UIView *subView4 = subView3.subviews[0];
UIView *subView5 = subView4.subviews[0];
// UILabel *title = subView5.subviews[0];//第一個(gè)是標(biāo)題,
//第二個(gè)是message
UILabel *message = subView5.subviews[1];
//改變message的對(duì)齊方式
message.textAlignment = NSTextAlignmentLeft;
.......
結(jié)束。