title: UIButton subclass, fill up SafeArea, inset content
body: <p>I'm getting the hang of using the safe area when using custom UI elements in <code>.xib</code>/<code>.storyboard</code>.</p>
  
  <p>I now have the case where I have a UIButton subclass that's used everywhere throughout the app. Since it's just a subclass (and not a custom class in <code>.xib</code>) I'm not sure how I would update this to fit my needs.</p>
  
  <p>See the following photo:
  <a href="https://i.stack.imgur.com/ayLHW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ayLHW.png" alt="iPhone X button"></a>
  Here the yellow is the UIButton. On 'regular' iPhones this yellow is the bottom of the screen.
  What I'm trying to achieve is to have the button go all the way to the bottom of the safe area, while still being in the same position (above the safe area).</p>
  
  <p>Normally I would constraint the button to <code>superview.bottom</code>, and in the button's <code>.xib</code> constraint the content (titleLabel, buttonImage, etc) to <code>safearea.bottom</code>.</p>
  
  <p>Since that's not possible here, how would I do that?</p>
  
  <p>I tried adding the constraints programatically in the UIButton subclass, but to not avail.</p>
  
  <p>Example:</p>
  
  <pre><code>if #available(iOS 11.0, *) {
      NSLayoutConstraint.activate([
          (titleLabel?.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor))!,
          (titleLabel?.bottomAnchor.constraint(equalTo: self.safeAreaLayoutGuide.bottomAnchor))!
          ])
  } else {
      // Fallback on earlier versions
  }
  </code></pre>
  
  <p>Thanks in advance!</p>