I am creating a subclass of NSButton to replicate the various button types seen in Xojo for example.
But when I create a pushbutton… the width of the button conforms to the caption, regardless of the width I specifiy.
so I get
* [ B ]
All my searching results in ways TO make this happen, when my code is doing it without any addition help
well darn… its is SOMETHING in my subclass… because if I do a raw NSButton
var xyz = NSButton(frame:NSRect(x:10,y:240,width:200,height:200))
xyz.bezelStyle = .rounded
this DOES work
Are you calling autoSize somewhere?
Nope… no autosize, no sizetofit.
The button with the problem is a subclass of a subclass since all basic buttons come from NSButton
Right now I’m in the process of stripping out as much as possible to get it to “work”… then slowly put things back… but I’ve taken out a ton, and the problem still exists
well I got it to work… with lord only knows how much code I commented out… but I think I have it narrowed to one method… which is shared with every control … so I have to be careful not to break something else… that is once I figure why it hates NSButton
///// subView.translatesAutoresizingMaskIntoConstraints = false
this command confuses the **** out of me… .Note I do not use Autolayout (at the moment)… and FALSE seems to work for evrything else… but for NSButton it doesn’t
Auto-layout is the bane of many Xcode developer!
Which is why I avoid it… but I fear for this project I’m going to have to use a little bit… I need to replicate the functions of LockLeft/Right/Top/Bottom, and the only other way I can think is to scan all the controls each time a window resizes and recalculate each one based on Deltas
Great (not)… turns out adding that line was fine UNTIL I live resize the window, and then it is as if LOCKRIGHT and LOCKBOTTOM were true … with no Autolayout code even specified anywhere
had to add this
self.widthAnchor.constraint(equalToConstant: self.frame.width).isActive = true
self.heightAnchor.constraint(equalToConstant: self.frame.height).isActive = true
Have you tried the auto resizing mask?
NSViewWidthSizable and so on. Because Mac Cocoa uses bottom-up co-ordinates, you also have to specify NSViewMinYMargin if you want it to lock to the top of the window.
I’m going to postpone dealing with this issue for the moment. Once I get all the controls working normally, I need to apply some kind of ability to replicate the Lock feature. This is going to require some specialized constraints… There is a “layout” class that I am having every control have an instance of, with the idea being that class will do all the work, so I only have to solve the issue once and all my controls will size using the same logic.