diff --git a/Sources/Earthquake Network/UI/EQNRoundedButton.swift b/Sources/Earthquake Network/UI/EQNRoundedButton.swift index 5ca8f7b..fe719f1 100644 --- a/Sources/Earthquake Network/UI/EQNRoundedButton.swift +++ b/Sources/Earthquake Network/UI/EQNRoundedButton.swift @@ -22,14 +22,36 @@ class EQNRoundedButton: UIButton { setupUI() } + // MARK: - Overrides + + override var intrinsicContentSize: CGSize { + get { + return titleLabel?.intrinsicContentSize ?? CGSize.zero + } + } + + override func layoutSubviews() { + // adapt button height to titleLabel size + titleLabel?.preferredMaxLayoutWidth = titleLabel?.frame.size.width ?? 0 + super.layoutSubviews() + } + // MARK: - Private private func setupUI() { + // add border layer.masksToBounds = true layer.borderWidth = AppTheme.shared.buttonBorderWidth layer.borderColor = AppTheme.Colors.gray.cgColor layer.cornerRadius = AppTheme.shared.buttonCornerRadius + // setup button for multiline title + titleLabel?.font = .preferredFont(forTextStyle: .body) + titleLabel?.lineBreakMode = .byWordWrapping + titleLabel?.textAlignment = .center + titleLabel?.numberOfLines = 0 + titleLabel?.adjustsFontForContentSizeCategory = true + setTitle(titleLabel?.text?.uppercased(), for: .normal) } }