【发布时间】:2015-03-07 16:08:09
【问题描述】:
我想更新通过drawInRect: withAttributes: 添加到NSView 中的文本。但是,似乎无法仅通过更改其属性来更新文本。
class MyView: NSView {
var str: NSString!
override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
str = "Sample Text"
str.drawInRect(NSMakeRect(0, 0, 60, 40), withAttributes: nil)
}
}
上面的代码为视图创建了文本Sample Text,我将它添加到了故事板上。
但是,当我尝试通过更改其属性或再次调用drawInRect: withAttributes: 来更新文本时,文本根本没有更新。代码如下:
@IBAction func callButton(sender: AnyObject) {
myView.str = "Test"
myView.str.drawInRect(CGRectMake(0, 0, 60, 40), withAttributes: nil)
}
为什么文本没有更新?另外,如何更新文本?
【问题讨论】: