美文网首页
swift实现UIAlertController文本左对齐

swift实现UIAlertController文本左对齐

作者: 通哥 | 来源:发表于2017-02-09 16:25 被阅读0次

1. 效果图

2. 代码截图

3. 代码

let alertController = UIAlertController(title: "", message: "考勤地点:上海市徐汇区桂平路391号有效范围:300米", preferredStyle: UIAlertControllerStyle.alert)

let subView1:UIView = alertController.view.subviews[0]

let subView2 = subView1.subviews[0];

let subView3 = subView2.subviews[0];

let subView4 = subView3.subviews[0];

let subView5 = subView4.subviews[0];

//取title和message:

let title:UILabel = subView5.subviews[0] as! UILabel

let message:UILabel = subView5.subviews[1] as! UILabel

message.textAlignment = NSTextAlignment.left

title.textAlignment = NSTextAlignment.left

let cancelAction = UIAlertAction(title: "我知道了", style: UIAlertActionStyle.cancel, handler: nil)

alertController.addAction(cancelAction)

self.present(alertController, animated: true, completion: nil)

相关文章