我有一个UILabel,用于显示多行文本。在显示文本的那一刻,它正对着标签的左手,看起来不太好。我希望文本从左边稍微插入。
到目前为止,这是我的代码:
if notes.objectAtIndex(indexPath.row) as NSString == "" {
cell.notesLabel.text = "No notes to display."
cell.notesLabel.textAlignment = NSTextAlignment.Center
} else {
cell.notesLabel.textAlignment = NSTextAlignment.Left
}
我当时在看一些Objective-C示例,但我无法使它们正常工作,我真的不认为它们就是我想要的。
另外,我试图用不同的标签做同样的事情,在那种情况下,我假设我可以在字符串的末尾添加“”(因为它是单行标签)以将其从右侧移入,但我惊讶地发现这行不通?
谢谢。
要从左边缘插入文本,您应该创建一个UILabel子类,并重写drawTextInRect :,
class RDLabel: UILabel {
override func drawTextInRect(rect: CGRect) {
let newRect = CGRectOffset(rect, 10, 0) // move text 10 points to the right
super.drawTextInRect(newRect)
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句