I fixed the one problem that I had with the app where I had allowed it to use landscape orientation. When the user rotated the device, the screen would go blank and the on-screen-keyboard would disappear. Rotating it back didn’t restore the keyboard making the app useless.

Now I need a Clear button. I am not sure how an iOS user interface is supposed to work. I have seen apps on various devices where text fields come with a clear button (and X) inside of the field. But the Bill Amount of the Tip Calculator is not a text field, it is just a text block being formatted with data from a hidden text field. I opted to stick in an X next to the Bill Amount.

20150205_222747000_iOS

New Tip Calculator

The first task was to find a button. I started with a button in xCode Interface Builder that contained the letter X. This was not good visually and also a bit hard to tap in the right place. The button seemed small. Then I discovered that xCode or iOS or Apple provide a few image buttons. There is no (X) button but there is a Plus Sign button. I added the Plus Sign button, added code to rotate it 45 degrees, and then changed some positioning numbers to make it bigger.

Line 21 is where the UIButton is declared and bound to the UI for the new button. Line 30 is where I rotate it.

There is no code file to display here for the positioning tweak. Here is an image of the Interface Builder.Screen Shot 2015-02-05 at 2.36.57 PM

xCode Tip Calculator Project

Over on the right side in the Attributes Inspector, there are settings for Top, Bottom, Left, and Right inset values. I just set some negative values until the button looked correct. I also had to change the Alignment settings to “stretch” to get the button to get bigger.

Some of the constraints needed to be changed to get the controls laid out properly on the screen. I think that I have it right, but I’m still unsure how to best constrain things since I’m new to xCode and Interface Builder.

There was almost no Swift coding to do for this small change. What I did need to do was simple and gave me no problems.

And yes, I like to put opening braces on their own line. Having them at the end of the line makes it hard to see if they are there or not. My formatting style allows me to see opening brace mistakes more quickly than the fairly typical brace-at-the-end-of-a-line formatting style.