mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-21 05:06:29 +00:00
49 lines
1.3 KiB
Swift
49 lines
1.3 KiB
Swift
// Copyright © 2021 Metabolist. All rights reserved.
|
|
|
|
import UIKit
|
|
|
|
final class FollowsYouLabel: UILabel {
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
initialSetup()
|
|
}
|
|
|
|
@available(*, unavailable)
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
|
|
layer.cornerRadius = inset
|
|
invalidateIntrinsicContentSize()
|
|
}
|
|
|
|
override func drawText(in rect: CGRect) {
|
|
super.drawText(in: rect.inset(by: .init(top: 0, left: inset, bottom: 0, right: inset)))
|
|
}
|
|
|
|
override var intrinsicContentSize: CGSize {
|
|
var size = super.intrinsicContentSize
|
|
|
|
size.width += inset * 2
|
|
|
|
return size
|
|
}
|
|
}
|
|
|
|
private extension FollowsYouLabel {
|
|
var inset: CGFloat { bounds.height / 2 }
|
|
|
|
func initialSetup() {
|
|
backgroundColor = .tertiarySystemBackground
|
|
textColor = .secondaryLabel
|
|
font = UIFont.preferredFont(forTextStyle: .footnote)
|
|
adjustsFontForContentSizeCategory = true
|
|
setContentHuggingPriority(.required, for: .horizontal)
|
|
setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
clipsToBounds = true
|
|
}
|
|
}
|