Ilya Loshkarev loshkarev.i@gmail.com
SFEDU 2016
Every view has underlying Core Animation layer
// Defines position of the view in it's parent
var frame: CGRect
// Defines bounding rectangle for view's content
var bounds: CGRect
// Array of all subviews contained in the view
var subview: [UIView]
// Access to underlying Core Animation
var layer: CALayer
UILabel | displays static text |
---|---|
UIPickerView | lets the user choose between certain options |
UIImageView | displays an image or an animated sequence of images |
UIWebView | can display HTML content |
Allows to display content bigger than view's boundaries
UITableView | presents data in a scrollable list of multiple rows |
---|---|
UICollectionView | displays an ordered collection of data items |
UITextView | accepts and displays multiple lines of text |
Conveys a particular action or intention to the app
through user interaction
UIButton | lets a user initiate behavior with a tap |
---|---|
UITextField | allows the user to input a single line of text |
UISwitch | lets the user turn an option on and off |
UISlider | enables users to interactively modify some adjustable value |
UIDatePicker | is used for selecting a specific date, time, or both |
Connects storyboard item to the code
@IBOutlet weak var myButton: UIButton!
Connects event handler to a control
@IBAction func buttonTouched(sender: UIButton) { }
Element must be removed from connections
when deleted
Auto Layout provides a set of constraints
to describe position and size of a view
in relation to its surrondings
Every view has 9 Layout Attributes
Every constraint describes relationship
between two attributes
Allows automatic alignment of contained views
for simplified layout
// Creaye new constraint
// myView.Leading = view.LeadingMargin * 1.0 + 0.0
let constraint = NSLayoutConstraint(
item: myView, attribute: .Leading,
relatedBy: .Equal,
toItem: view, attribute: .LeadingMargin,
multiplier: 1.0, constant: 0.0)
// Activate new constraint
constraint.active = true
// Recalculate view's dimentions
myView.layoutIfNeeded()
// Remove new constraint
myView.removeConstraint(constraint)
A navigation bar can display a left button, title, prompt string and right button(s)
Editor → Embed In → Navigation Controller
Provides easy access to different views in an app
Each view can be a start of separate view stack
Can be divided into sections
Each section contains
any number of cells
Able to present static or
dynamic content
Each prototype cell describes appearence of
multiple cells in the table
Each prototype cell has a Reuse Identifier
// Returns the label used for the main textual content of the table cell
var textLabel: UILabel?
// Returns the secondary label of the table cell if one exists
var detailTextLabel: UILabel?
// Returns the image view of the table cell
var imageView: UIImageView?
override func tableView(tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
return 5
}
override func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("RobinTheMan",
forIndexPath: indexPath)
cell.textLabel.text = String(indexPath.row)
return cell
}
A segue represents the transition from one scene
to the next scene
Show | Push on top of main stack | |
---|---|---|
Show Detail | Push on top of detail stack | |
Present in Popover | Show in popover view | |
Present Modally | Show on top of current root view | |
Custom | Custom Segue |