SHARE
TWEET

Untitled

a guest Apr 19th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import UIKit
  2.  
  3. class MultiLineButton: UIButton {
  4.  
  5.     // MARK: - Init
  6.  
  7.     required init?(coder aDecoder: NSCoder) {
  8.         super.init(coder: aDecoder)
  9.  
  10.         self.commonInit()
  11.     }
  12.  
  13.     private func commonInit() {
  14.         self.titleLabel?.numberOfLines = 0
  15.         self.titleLabel?.lineBreakMode = .byWordWrapping
  16.     }
  17.  
  18.     // MARK: - Overrides
  19.  
  20.     override var intrinsicContentSize: CGSize {
  21.         get {
  22.              return titleLabel?.intrinsicContentSize ?? CGSize.zero
  23.         }
  24.     }
  25.  
  26.     override func layoutSubviews() {
  27.         super.layoutSubviews()
  28.         titleLabel?.preferredMaxLayoutWidth = titleLabel?.frame.size.width ?? 0
  29.         super.layoutSubviews()
  30.     }
  31.  
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top