forked from HabitRPG/habitica-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaddedLabel.swift
31 lines (25 loc) · 1020 Bytes
/
PaddedLabel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// PaddedView.swift
// Habitica
//
// Created by Phillip Thelen on 27/02/2017.
// Copyright © 2017 HabitRPG Inc. All rights reserved.
//
import UIKit
class PaddedLabel: UILabel {
@objc public var horizontalPadding: CGFloat = 8.0
@objc public var verticalPadding: CGFloat = 4.0
override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
return CGSize(width: size.width+horizontalPadding*2, height: size.height+verticalPadding*2)
}
override func sizeThatFits(_ size: CGSize) -> CGSize {
let fittingSize = super.sizeThatFits(size)
return CGSize(width: fittingSize.width+horizontalPadding*2, height: fittingSize.height+verticalPadding*2)
}
override func sizeToFit() {
super.sizeToFit()
let paddedSize = CGSize(width: frame.size.width+horizontalPadding*2, height: frame.size.height+verticalPadding*2)
frame = CGRect(x: 0, y: 0, width: paddedSize.width, height: paddedSize.height)
}
}