Class UILabel

Like the Touch app, This with has than one UIView object (not counting the UIWindow object). As usual, we have a big white UIView that fills the screen. We also have a small yellow UIView that is inserted as a subview into the big white UIView. The small yellow view is a UILabel.

A UILabel is a specialized type of UIView. In other words, class UILabel is a subclass of class UIView. A UILabel is specialized for holding and displaying one line of text. It can display the line without the call to drawAtPoint(_:withAttributes:) in drawRect(_:) that we saw here. In fact, it can display the line without any drawRect(_:) method at all.

Source code in Label.zip

  1. Class AppDelegate.swift
  2. Class ViewController.swift
  3. Class View.swift. I added the init that takes an NSCoder. But this is the first time I did not add drawRect.

Things to try

  1. Change the label’s font size from 32 to UIFont.labelFontSize().