Programmatically created NSButton is drawn in the wrong position.
Programmatically created NSButton is drawn in the wrong position.
- Subject: Programmatically created NSButton is drawn in the wrong position.
- From: Eyal Redler via Cocoa-dev <email@hidden>
- Date: Tue, 15 Dec 2020 03:39:01 +0200
I'm configuring a view with some push buttons and other views programmatically
and the buttons are drawn offset to the right.
For example, the first button should be at 0,20 but it is drawn at 6,20. I
checked that the buttons are not moved, the button frames remain the same, the
buttons are just drawn 6 points to the right.
Here's a screenshot: https://s3.amazonaws.com/mellel.outbox/button_woes.png
Here's the code:
NSView* _view = [_window contentView];
CGFloat position;
position = 0;
for (NSString* buttonTitle in @[@"button one",@"button two",@"button three"])
{
NSButton* button;
button = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
[button setTranslatesAutoresizingMaskIntoConstraints:NO];
[button setBezelStyle:NSRoundedBezelStyle];
[button setTitle:buttonTitle];
[button sizeToFit];
[button setFrameOrigin:NSMakePoint(position, 20)];
[_view addSubview:button];
position += [button frame].size.width + 8;
}
Thanks in advance,
Eyal Redler
------------------------------------------------------------------------------------------------
"If Uri Geller bends spoons with divine powers, then he's doing it the hard
way."
--James Randi
www.eyalredler.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden