I’ve also been trying to figure out how to to put the view controllers into Landscape mode.
So this is a post in two parts. landscape view controllers, and rounded UIButtons.
1, this is not using images, nor background images of any type. It’s just using the plain vanilla UIButton that comes with the standard XCode 5.1.1, and iOS7.1 SDK.
This is also a note for me for future reference as well.
You can test it out easily. Make a Test app. Call it errr, TestApp. You can set it up as a Universal if you like. Practice on both iPhone and iPad interfaces.
Firstly: Landscape view controller.
Click on the black bar just to the bottom of the actual view controller. This will cause the view controller and the bar to have a blue surrounding.
Now, click on the little shield fourth to the right in the top right hand side. The Show Attribute Inspector.
Set Orientation to Landscape. Don’t touch anything else. In this example I have already Embedded the view controller in a Navigation Controller so the rest of the app will work…
Now, for the buttons. Note here, that the buttons DO NOT appear to be rounded when sitting in the viewcontroller. It’s only when compiled and running in the Simulator/Device that they are reounded. See the later screen shot.
Click on the Main_iPhone.storyboard and there, drag a UIButton into the view controller.
Still with the Attribute Inspector selected, change the button type to Custom. Note I set the button background to a purple colour so I can clearly see the shape when it runs.
Now this bit isa bit trickier. Take your time with this.
With the button still selected, click on the little button Third from the left in the top tab bar, next to the Attribute inspector, called Identity Inspector. Not the Very top right row, the second top right row, it looks kind of like a tiny screen layout? Look in the image following here.
With the Button selected in the view controller – (Not the ViewController, or you will have a view controller with rounded corners. Not at all bad I guess … but not what we want here.)
Select in Custom Class -> Class -> UIButton. (If you don’t find it in the list from the drop-down, type it in… then look again.) I had to fiddle with this a bit to get it to appear.
Once you have UIButton in the Class field, time to do the next bit.
You have to add information to the “User Defined Runtime Attributes” by tapping the + button for that section.
Don’t be dismayed by what you see there, it’s a place holder. Double click the KeyPath and change it to what you see here in the image.
layer.cornerRadius Number 10
layer.masksToBounds Boolean tick
Nothing will change, but when you run the app in the simulator – there is your rounded button.