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 Build a Simple iPhone App with Swift Views and View Controllers View Controllers and IBAction

Hariidaran Tamilmaran
seal-mask
.a{fill-rule:evenodd;}techdegree
Hariidaran Tamilmaran
iOS Development Techdegree Student 19,305 Points

Button not centring on iPhone Screen

The button, when placed on the iPhone screen, does not centre on the simulator. Why does that happen? Can you tell me how to centre it on the simulator.

ViewController.swift
@IBAction func showFunFact() {
        funFactLabel.text = factBook.randomFact() //This line here
}

And when I run the project, I click the button, then I suddenly go back to the editor, and on that line I get "Thread 1: breakpoint 1.1". Please help!

2 Answers

Anthony Martinez
Anthony Martinez
13,111 Points

hey there. open up your main.storyboard and locate the UI element (the button) and add some constraints to the button.

constraints have the net effect of locking your UI element wherever you place it. you can be very specific with your constraints.

if there are other elements in the view, you can use them as references, meaning you can have your button a certain vertical height from another UI element.

i highly recommend pasan's 'build a simple iPhone app with Objective-C', though you'll definitely do a lot more UI element management & design in his 'build a playlist browser' course.

check out his 'Improving Our User Interface' unit in his 'build a simple iPhone app with Objective-C' class!

Andrew Giese
Andrew Giese
2,925 Points

I think the easiest explanation is to go to your storyboard where you can see your button and then;

1) Select your button

2) Click on the align button on the lower right hand of your view controller (it looks like a | with two rectangles next to it.)

3) A menu entitled add new alignment constraints should pop up.

4) Select both Align Horizontally and Align Vertically.

5) Hit add constraints.

Hariidaran Tamilmaran
seal-mask
.a{fill-rule:evenodd;}techdegree
Hariidaran Tamilmaran
iOS Development Techdegree Student 19,305 Points

Yeah, I got the entering thing. Thanks. But when I run the project, I click the button, THEN I suddenly go back to the editor, and on that line I get "Thread 1: breakpoint 1.1". Help!