我试图将UILabel分为3部分,顶部是标题,第二行是艺术家,第三行是专辑。为什么UILabel没有以三行显示它?
var ID3 = UILabel(frame: CGRectMake(0,0,200,200))
ID3.center = CGPointMake(160, 284)
ID3.textAlignment = NSTextAlignment.Center
ID3.text = (Title + "\n" + Artist + "\n" + Album)
self.view.addSubview(ID3)
答案 0 :(得分:1)
ID3.numberOfLines = 3
希望有帮助;)此属性的默认值为1,如果将其设置为0,则您将拥有多行标签:)
编辑: 示例游乐场代码:
//: Playground - noun: a place where people can play
import UIKit
let Title = "Lorem ipsum title"
let Artist = "lorem ipsum artist"
let Album = "lorem ipsum album"
var ID3 = UILabel(frame: CGRectMake(0,0,200,200))
ID3.center = CGPointMake(160, 284)
ID3.textAlignment = NSTextAlignment.Center
ID3.text = (Title + "\n" + Artist + "\n" + Album)
ID3.numberOfLines = 3
ID3.backgroundColor = UIColor.redColor()
var view = UIView(frame: CGRectMake(0, 0, 500, 500))
view.backgroundColor = UIColor.whiteColor()
view.addSubview(ID3)