0

自定义类:

class FancyLabel: UILabel {

  let padding  = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

  override func drawRect(rect: CGRect) {
    super.drawTextInRect(UIEdgeInsetsInsetRect(rect, padding))
   }
}

在我的视图控制器中:

let myframe = CGRectMake(10, 10, some_width, some_height)
let myLabel = FancyLabel(frame: myframe)
myLabel.textAlignment = NSTextAlignment.Center
myLabel.text = text
myLabel.numberOfLines = 0
myLabel.sizeToFit()
self.myScrollView.addSubview(myLabel)

结果是这样的:

缺少 UILabel 的最后一行

4

0 回答 0