beginning ios6 development ch04 more user interface fun
Post on 22-Nov-2014
640 Views
Preview:
DESCRIPTION
TRANSCRIPT
User Interface
1iabdulrazzaq@outlook.comEng. Abdulrazzaq Alnajjar
A Screen Full of Controls
• What to learn:
– Image view
– Text field
– Slider
– Segmented control
– Switch
– action sheet
– Alert
2iabdulrazzaq@outlook.comEng. Abdulrazzaq Alnajjar
Controls
• Active
• Static
• Passive
– most of the available controls can be used in all three modes.
– All iOS controls are subclasses of UIControl.
iabdulrazzaq@outlook.com 3Eng. Abdulrazzaq Alnajjar
Differences of Controls on iOS
• Because of the multitouch interface, all iOS controls can trigger multiple actions depending on how they are touched.
• You could have one action fire when the user presses down on a button and a separate action fire when the finger is lifted off the button.
• You could have a single control call multiple action methods on a single event.
• iOS devices do not have a physical keyboard.
iabdulrazzaq@outlook.com 4Eng. Abdulrazzaq Alnajjar
Image View
• Drag an image view onto the view in the nib editor.
iabdulrazzaq@outlook.com 5Eng. Abdulrazzaq Alnajjar
Image View
• Resizing the Image View
– resize the image view to match the size of its contents. select Editor ➤ Size to Fit Content.
• Alignment
– Editor ➤ Align ➤ Horizontal/Vertical Center in Container
• Draw a outline
– Editor ➤ Canvas ➤ Show Bounds Rectangles
iabdulrazzaq@outlook.com 6Eng. Abdulrazzaq Alnajjar
Image View Attributes
• Attributes
– The Mode Attribute
– Tag
– Interaction Checkboxes
– The Alpha Value
– Background
– Drawing Checkboxes
– Stretching
iabdulrazzaq@outlook.com 7Eng. Abdulrazzaq Alnajjar
Image View Attributes
1) The Mode menu defines how the view will display its content.
– choosing any option that causes the image to scale will potentially add processing overhead, so it’s best to avoid those and size images correctly before importing them.
iabdulrazzaq@outlook.com 8Eng. Abdulrazzaq Alnajjar
Image View Attributes
2) Tags provide an easy, language-independent way of identifying objects on your interface.
3) Interaction Checkboxes:
– User Interaction Enabled: specifies whether the user can do anything at all with this object
– Multiple Touch: determines whether this control is capable of receiving multitouch events.
iabdulrazzaq@outlook.com 9Eng. Abdulrazzaq Alnajjar
Image View Attributes
4) Alpha defines how transparent your image is—how much of what’s beneath it shows through.
– It’s defined as a floating-point number between 0.0 and 1.0, where 0.0 is fully transparent and 1.0 is completely opaque.
5) Background determines the color of the background for the view.
iabdulrazzaq@outlook.com 10Eng. Abdulrazzaq Alnajjar
Image View Attributes
6) Drawing Checkboxes:
– Opaque: tells iOS that nothing behind this view ever needs to be drawn no matter what.
– Hidden: hides an object.
– Clears Graphics Context: draws the entire area covered by the object in transparent black before it actually draws the object.
iabdulrazzaq@outlook.com 11Eng. Abdulrazzaq Alnajjar
Image View Attributes
6) Drawing Checkboxes(cont.):
– Clip Subviews: If checked, only the portions of subviews that lie within the bounds of the parent will be drawn. If unchecked, subviews will be drawn completely, even if they lie outside the bounds of the parent.
– Autoresize Subviews tells iOS to resize any subviews if this view is resized.
iabdulrazzaq@outlook.com 12Eng. Abdulrazzaq Alnajjar
Image View Attributes
7) Stretching
– The four floating-point values set here let you declare which portion of the rectangle is stretchable by specifying a point at the upper-left corner of the view and the size of the stretchable area, all in the form of a number between 0.0 and 1.0, representing a portion of the overall view size
iabdulrazzaq@outlook.com 13Eng. Abdulrazzaq Alnajjar
Text Fields
• Grab 2 text fields & 2 labels from the library into the View.
iabdulrazzaq@outlook.com 14Eng. Abdulrazzaq Alnajjar
Text Field Inspector Settings
iabdulrazzaq@outlook.com 15Eng. Abdulrazzaq Alnajjar
Text Field Inspector Settings
• Text
• Placeholder
• font
• font color
• Background and Disabled.
• Border Style
• Clear Button & Clear when editing begins checkbox
• Adjust to Fit checkbox
iabdulrazzaq@outlook.com 16Eng. Abdulrazzaq Alnajjar
Text Field Inspector Settings
• Keyboard:– Capitalization
– Correction
– Keyboard
– Appearance
– Return Key
– Auto-enable Return Key checkbox
– Secure checkbox
• Control: Enabled checkbox
iabdulrazzaq@outlook.com 17Eng. Abdulrazzaq Alnajjar
Creating and Connecting Outlets
• s
iabdulrazzaq@outlook.com 18Eng. Abdulrazzaq Alnajjar
Closing the Keyboard
• In header file:
iabdulrazzaq@outlook.com 19Eng. Abdulrazzaq Alnajjar
Closing the Keyboard
• In implementation file(before @end):
• From connections inspector Drag from the circle next to Did End On Exit to the textFieldDoneEditing: method.
iabdulrazzaq@outlook.com 20Eng. Abdulrazzaq Alnajjar
Touching the Background to Close the Keyboard
• In header file:
iabdulrazzaq@outlook.com 21Eng. Abdulrazzaq Alnajjar
Touching the Background to Close the Keyboard
• In implementation file(before @end):
• Go to identity inspector: change class into UIControl
• Connect the view’s Touch Down event to the backgroundTap: action
iabdulrazzaq@outlook.com 22Eng. Abdulrazzaq Alnajjar
Slider
• A slider lets you choose a number in a given range.
• Minimum, Maximum and Current values.
iabdulrazzaq@outlook.com 23Eng. Abdulrazzaq Alnajjar
Slider Actions and Outlets
• Slider Action: Set the Type to UISlider.
• Label outlet.
• Slider Action method:
• Set current value:
24iabdulrazzaq@outlook.comEng. Abdulrazzaq Alnajjar
Segmented Control & Switches
• Segmented Control used to show & hide objects.
• Switches are small controls that can have only two states: on and off.
iabdulrazzaq@outlook.com 25Eng. Abdulrazzaq Alnajjar
Segmented Control & Switches
• Add a segmented control & 2 switches.
• Create Outlets (rightSwitch, leftSwitch)and one action(switchChanged) for the two switches.
– set the Type of its sender to UISwitch.
• Create an action(toggleControls) for the segmented control.
– set the Type of its sender to UISegmentedControl.
iabdulrazzaq@outlook.com 26Eng. Abdulrazzaq Alnajjar
Segmented Control & Switches
• Switch Actions:
iabdulrazzaq@outlook.com 27Eng. Abdulrazzaq Alnajjar
Segmented Control & Switches
iabdulrazzaq@outlook.com 28
• Add a button directly on top of the two switches.
– create an outlet (doSomethingButton) & an action (buttonPressed).
• Check the buttons Hidden checkbox.
Eng. Abdulrazzaq Alnajjar
Segmented Control & Switches
• segmented control action:
iabdulrazzaq@outlook.com 29Eng. Abdulrazzaq Alnajjar
Action Sheet and Alert
• Action sheets are used to force the user to make a choice between two or more items.
• Alerts force users to respond before they are allowed to continue using the application
iabdulrazzaq@outlook.com 30Eng. Abdulrazzaq Alnajjar
Action Sheet and Alert
• Action sheet action:
– Then add a method after the buttonPressed: method
iabdulrazzaq@outlook.com 31Eng. Abdulrazzaq Alnajjar
iabdulrazzaq@outlook.com 32Eng. Abdulrazzaq Alnajjar
viewDidLoad Method
• viewDidLoad helps to modify any of the objects that were created in nib file.
iabdulrazzaq@outlook.com 33Eng. Abdulrazzaq Alnajjar
viewDidLoad Method
iabdulrazzaq@outlook.com 34Eng. Abdulrazzaq Alnajjar
viewDidLoad Method
• The former code sets the background image for the button.
• It specifies that, while being touched, the button should change from using the white image to the blue image. This short method introduces two new concepts: control states and stretchable images.
iabdulrazzaq@outlook.com 35Eng. Abdulrazzaq Alnajjar
Control States
• Every iOS control has four possible control states:– Normal: is the default state. It’s the state that controls are
in when not in any of the other states.
– Highlighted: is the state a control is in when it’s currently being used.
– Disabled: when they have been turned off, which can be done by unchecking the Enabled checkbox in Interface Builder or setting the control’s enabled property to NO.
– Selected: It is usually used to indicate that the control is turned on or selected. Selected is similar to highlighted, but a control can continue to be selected when the user is no longer directly using that control.
iabdulrazzaq@outlook.com 36Eng. Abdulrazzaq Alnajjar
Stretchable Images
• A stretchable image is a resizable image that knows how to resize itself intelligently so that it maintains the correct appearance.
– Edge insets are the parts of an image, measured in pixels, that should not be resized.
iabdulrazzaq@outlook.com 37Eng. Abdulrazzaq Alnajjar
top related