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!
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
I'm having trouble understanding the docs at times. Where is it shown that you can access the width and height by doing frame.size.width/height?
Lee Watkins11,345 Points
This is a good questions, and the vague answer is that it takes practice. Here's how you would go about this:
You would have learnt so far that UIViewControllers etc are all subclasses of UIView. The frame is a property of UIView, so you can start looking in Apple's UIView Reference docs here. In those docs you'll find that UIView has a
If you expand the
frame property you will see that it's of type CGRect. That means that the
frame property is a CGRect struct, and to get more information on it, you'll need to view the CGRect Reference documentation. You can do this by clicking on 'CGRect' in the definition of the
Navigating to the CGRect Reference documentation, you'll find that this struct consists of two "sub-structs":
size. These are structs of type CGPoint and CGSize respectively. CGSize contains two values:
So what you now know is that:
- UIView contains a property called
frameof type CGRect
- CGRect contains two structs, one is the
sizeof type CGSize
- CGSize contains two values,
This drill-down of properties is how we find that we can set
There is, of course, an easier way, and that is by searching tutorials and so on. However, if you understand how to drill drown into the documentation, it can be very useful.
I hope this helps, and let me know if you have any further questions.
Thank you Lee,I kinda figured it out eventually after I kept looking at the documentation but I agree with you, it just takes practice. The biggest issue I have with iOS development is that I started off with Swift and I understood the tutorials but there don't seem to be enough examples or code samples using the new syntax. So I decided to do all the Objective C stuff and then try and translate them to Swift as a way of learning.
Thank you for responding.