美文网首页
iOS 8UIAlertcontroller如何实现 messa

iOS 8UIAlertcontroller如何实现 messa

作者: 流沙3333 | 来源:发表于2017-03-10 11:11 被阅读96次

    实例化alertcontroller之后,可以遍历view的子视图,子视图title和message嵌套了多层父视图,(需要遍历6层subViews),

    下面是取title和message的父视图的代码:

    UIView *subView1 = alert.view.subviews[0];

    UIView *subView2 = subView1.subviews[0];

    UIView*subView3 = subView2.subviews[0];

    UIView*subView4 = subView3.subviews[0];

    UIView*subView5 = subView4.subviews[0];

    取title和message:

    UILabel*title = subView5.subviews[0];

    UILabel*message = subView5.subviews[1];

    然后设置message内容居左:

    message.textAlignment = NSTextAlignmentLeft;

    swift版:

    let alert =UIAlertController(title:"版本升级", message: message,preferredStyle: .Alert)

    let subView = alert.view.subviews[0].subviews[0].subviews[0].subviews[0].subviews[0]

    let msgLabel = subView.subviews[1]as?UILabel

    msgLabel?.textAlignment= .Left

    相关文章

      网友评论

          本文标题:iOS 8UIAlertcontroller如何实现 messa

          本文链接:https://www.haomeiwen.com/subject/pxungttx.html