改變UIAlertController提示title和message的對(duì)齊格式

我們用的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é)束。

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

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

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