troubleshooting Question

Programmatically Add UI Controls in Objective-C

Avatar of varBoomer
varBoomer asked on
Programming Languages-OtherProgrammingSwift ProgrammingObjective-C Programming
2 Comments1 Solution1378 ViewsLast Modified:
I'm pretty new to Objective-C, but I do understand a lot of the syntax and the way it handles objects through messages.  But that's about it.  

One thing I'm trying to learn is how to add UI controls programmatically and I found some sample code to try and do this.  However, I'm not sure what method I need to "paste" the following code into.  It's for an NSButton.  

This is the sample code I found:
NSView *superview = [window contentView]; 
NSRect frame = NSMakeRect(10, 10, 200, 100); 
NSButton *button = [[NSButton alloc] initWithFrame:frame]; 
[button setTitle:@"Click me!"]; 
[superview addSubview:button]; 
[button release];

Any help is appreciated!
ASKER CERTIFIED SOLUTION
pgnatyuk

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros