Sunday, November 5, 2017

Implement a Custom Control

Back | Forward



Chapter 4 of 10 at Apple Developer > Jump Right In is Implement a Custom Control.


This is another chapter that never tells you, just expects, that you will start by jumping to the end of it and downloading a folder with an Images folder inside of it, so you can borrow those Png images when you need them.


The Fix-It buttons help


The newer versions of Xcode get more right by default. Don't expect Apple's guess of how much you need to fix to be correct. Just focus on taking the coding suggestions from Xcode.


<= Learning Objectives
<= Create a Custom View


Watch the Outline View closely


Apple means to ask you to land your Horizontal Stack View that becomes Rating Control at the bottom inside the UIStackView that vertically stacks your Meal Name Label, Name Text Field, and Photo Image View.

They never quite get around to asking for this out loud. Your results will match theirs much more closely if you pick up on this point. 

<= Display the Custom View


Match dimensions


Your Storyboard and App will look more like Apple's if you tell Utilities > Size Inspector to make your Horizontal Stack view have Width = 252 and Height = 44. That's because they're working with 5 of the 44x44 buttons at a Spacing of 8, and 252 == ((5 * 44) + (4 * 8)).

<= Add Buttons to the View


Help Interface Builder sketch your app


Do work thru adding support for Interface Builder, even though all that's wrong before you do is an inaccurate Storyboard, none of the errors and warnings that Apple explains used to haunt us.

<= Add Support for Interface Builder
<= Add Star Images to the Buttons


Keep the prints


You can keep the print statements, they trace what happens, they do no harm.

You'll have to keep the "@objc" fix-it for "func ratingButtonTapped", the code won't build otherwise.

The call to "updateButtonSelectionStates" from "setupButtons" isn't needed and does no harm.

<= Implement the Button Action


Try a real phone


The iPhone Simulator doesn't demo Settings > General > Accessibility > VoiceOver. You need a real phone for that, until we can get Apple to make more of a commitment to Accessibility.

To try a real phone, you need a friend with an Apple Developer subscription. US$100 per year plus tax was the cost to your friend, as of 2017.

<= Add Accessibility Information


Cooperate



Apple throws some more chores in here at random for you, not yet needed, but useful later. You may as well go along.

<= Connect the Rating Control to the View Controller
<= Clean Up the Project



Don't test Landscape View now


Apple doesn't mention that you've made only the portrait view work. You've broken the landscape view for devices smaller than an iPad.

Don't worry about it. You'll fix it soon enough.

<= Wrapping Up

 

Download and compare and commit



The download is 04_ImplementACustomControlYour Commit Message can be "Implement a Custom Control". 

<= Wrapping Up



Back | Forward | Source: Apple Developer >
 Implement a Custom Control

No comments: