How to add line break for UILabel?

后端 未结 21 2120
失恋的感觉
失恋的感觉 2020-11-29 14:53

Let see that I have a string look like this:

NSString *longStr = @\"AAAAA\\nBBBBB\\nCCCCC\";  

How do I make it so that the UILabel disp

21条回答
  •  醉梦人生
    2020-11-29 15:34

    In Swift 2.2, > iOS 8

    I've set Lines = 0 on Storyboard, under Attribute Inspector and linked a referencing outlet to the label. Then use in controller like this:

     @IBOutlet weak var listLabel: UILabel!
    
     override func viewDidLoad() {
          ...
          listLabel.text = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8"
     }
    

提交回复
热议问题