Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How can I get the width and height of the UIView created in the storyboard?

I just created a UIView in the storyboard and set the height to 200, and width to 30 in the storyboard. However, after I drag it to the coding and write:

CGRect graphFrame = CGRectMake(0, 0, self.graphView.frame.size.width, self.graphView.frame.size.height);
NSLog(@"Width: %f, Height: %f", graphFrame.size.width, graphFrame.size.height);

It always print out 320, 568; Instead of the 30, 200

1 Answer

Personally I hate using CGRectMake. I would recommend using Masonry cocoa pod. It really makes interface building easier through code.

If you don't know what CocoaPods is, here is a funny video from Google: Route 85: An Introduction to CocoaPods