I have views to present to mouser which can have two states: editing or noediting
In non editing state, the user can only see informations.textfields are not editable and not bezeled:
iif the user has authorization, he can push a button in the toolbar and the view enter editing mode:
in some of my views, I have a combobox
I have subclassed this combo so that in non editing mode, it is replaced by a NSTextField
My code is the following (I just write what I think is necessary, for bigger clarity):
class myControlCombo: NSComboBox {
var myHiddenText: NSTextField!
var state: etatWindow = .nonedition
override var stringValue: String {
get {
return super.stringValue
}
set (S) {
myHiddenText.stringValue = S
super.stringValue = S
}
}
required init?(coder: NSCoder) {
super.init(coder: coder)
myHiddenText = NSTextField(frame: self.frame)
myHiddenText.isBezeled = false
myHiddenText.isEditable = false
myHiddenText.font = self.font
self.superview?.addSubview(myHiddenText)
}
override func draw(_ dirtyRect: NSRect) {
if state == .nonedition {
myHiddenText.draw(dirtyRect)
} else {
super.draw(dirtyRect)
}
}
func setState (state: etatWindow, couleur: NSColor) {
self.state = state
if (state == .nonedition) {
isSelectable = false
//isBezeled = false
isButtonBordered = false
isEditable = false
backgroundColor = couleur
myHiddenText.isHidden = false
} else {
backgroundColor = couleur
//isBezeled = true
isButtonBordered = true
isSelectable = true
isEditable = true
myHiddenText.isHidden = true
}
}
}
I have the following problem: in non editing mode, when the NSTextField is displayed instead of the combobox it is not properly aligned and the font is not correct
Any Ideas why?