Chapter 38: Polish the Pop-up :: Page 941 Exercises. My Solution Attempts

iOS Apprentice, 6th edition

Page 941 Exercises. My Solution Attempts

Chapter 38: Polish the Pop-up :: Test Dynamic Type :: Page 941

Exercise. Set up the cells from the table view for Dynamic Type.

SearchResultCell.xib

I set nameLabel font to Headline and artistNameLabel font to Subhead.
I modified it using stackviews in next exercise.

SearchResultCell.swift

override func awakeFromNib() {
  super.awakeFromNib()

  // Set selectedView backgroundColor
  ...
  
  /// Exercise - UILabel's adjustsFont property
  nameLabel.adjustsFontForContentSizeCategory = true
  artistNameLabel.adjustsFontForContentSizeCategory = true
}

SearchViewController.swift

I created a Notification Listener to listen for a font size change notification.

func listenForContentSizeChangeNotification() {
  NotificationCenter.default.addObserver(
    forName: Notification.Name.UIContentSizeCategoryDidChange,
        object: nil,
        queue: OperationQueue.main) { [weak self] _ in
          guard let weakSelf = self else { return }
          weakSelf.tableView.reloadData()
          print("*** FontSizeDidChange. Reloaded tableView")
  }
}

Then called it from viewDidLoad()

override func viewDidLoad() {
  super.viewDidLoad()

  // Insets & searchBar set up
  ...

  /// Exercise - Notification Listener
  listenForContentSizeChangeNotification()

  // CellNib tableView registers
  ...
}

Page 941 Exercise. My Solution Attempt

Chapter 38: Polish the Pop-up :: Stack Views :: Page 941

Exercise. See if you can build the Detail pop-up with stack views.

UIStackView

SearchResultCell.xib
image

View Original

image


UIStackView

SearchViewController
image

View Original

image

Document Outline Details

View Details

Constraint Detail → Body

image

→ Price, Detail, Proportional Container, Pop-up View
image


1 Like