I have an textfield, drawn inside a NSButton. The setup is working. The button, the textfield and the value are shown:
Here´s the code how i setup the textfield:
class myButton: NSButton {
var textfield = NSTextField()
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
drawtextfield(text: "hello")
}
func drawtextfield(text: String) {
let dirtyRect = NSRect()
textfield.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: self.frame.width, height: self.frame.height)
textfield.stringValue = text
textfield.draw(dirtyRect)
}
}
now if i call:
myButton.init().drawtextfield(text: "hello2")
I´m getting error: CGContextSetCMYKStrokeColor: invalid context 0x0
How is it possible, that the textfield is drawn by the start of the app and when the function drawtextfield()
is called just a second time, i´m getting error? Advice would be much appreciated.