Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build an Interactive Story App with Swift Creating the User Interface Programmatically Creating Views Programmatically

Anchoring to the bottom the of the navigation

How would you anchor the top anchor of the image to the bottom anchor of the navigation in the controller ?

1 Answer

anglin
anglin
8,105 Points

I'm basing this answer off of one of the answers from http://stackoverflow.com/questions/17074365/status-bar-and-navigation-bar-appear-over-my-views-bounds-in-ios-7/18976660#18976660

Programmatically, you could adjust for it by adding the length of the "topLayoutGuide" as a constant to the constraint:

let topAdjust = self.topLayoutGuide.length

NSLayoutConstraint.activate([
        artworkView.topAnchor.constraint(equalTo: view.topAnchor, constant: topAdjust),
       // other constants same
])

Note: all the other constraints would remain the same, you just need to add the extra "constant" parameter to the artworkView.topAnchor.constraint