Files
eqn.ios/Sources/Earthquake Network/UI/EQNEdgeInsetLabel.swift
T
2020-07-30 21:08:50 +02:00

31 lines
971 B
Swift

//
// EQNEdgeInsetLabel.swift
// Earthquake Network
//
// Created by Busi Andrea on 30/07/2020.
// Copyright © 2020 Earthquake Network. All rights reserved.
//
import Foundation
class EQNEdgeInsetLabel: UILabel {
var textInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 15) {
didSet { invalidateIntrinsicContentSize() }
}
override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
let insetRect = bounds.inset(by: textInsets)
let textRect = super.textRect(forBounds: insetRect, limitedToNumberOfLines: numberOfLines)
let invertedInsets = UIEdgeInsets(top: -textInsets.top,
left: -textInsets.left,
bottom: -textInsets.bottom,
right: -textInsets.right)
return textRect.inset(by: invertedInsets)
}
override func drawText(in rect: CGRect) {
super.drawText(in: rect.inset(by: textInsets))
}
}