centering text in a UILabel with an NSAttributedString

后端 未结 3 651
清歌不尽
清歌不尽 2021-02-02 06:57

Going through some basic improvements to a application I am working on. Still new to the iOS swift development scene. I figured that the lines of text in my code would automatic

3条回答
  •  孤街浪徒
    2021-02-02 07:24

    In Swift 4.1 :

    let style = NSMutableParagraphStyle()
    
    style.alignment = NSTextAlignment.center
    
    lbl.centerAttributedText = NSAttributedString(string: "Total Balance",attributes: [.paragraphStyle: style])
    

    (edited for code block)

提交回复
热议问题