Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // RoundedLabel.swift
- //
- // Created by Vasily Ulianov on 20.10.16.
- //
- import UIKit
- @IBDesignable
- class RoundedLabel: UILabel {
- var edgeInsets: UIEdgeInsets {
- if autoPadding {
- if cornerRadius == 0 {
- return UIEdgeInsetsZero
- } else {
- return UIEdgeInsets(top: 1, left: 3, bottom: 1, right: 3)
- }
- } else {
- return UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
- }
- }
- @IBInspectable var horizontalPadding: CGFloat = 0
- @IBInspectable var verticalPadding: CGFloat = 0
- @IBInspectable var autoPadding: Bool = true
- @IBInspectable var cornerRadius: CGFloat = 0 {
- didSet {
- layer.cornerRadius = cornerRadius
- layer.masksToBounds = cornerRadius > 0
- }
- }
- override func drawTextInRect(rect: CGRect) {
- super.drawTextInRect(UIEdgeInsetsInsetRect(rect, edgeInsets))
- }
- override func intrinsicContentSize() -> CGSize {
- var size = super.intrinsicContentSize()
- let edgeInsets = self.edgeInsets
- size.width += edgeInsets.left + edgeInsets.right
- size.height += edgeInsets.top + edgeInsets.bottom
- return size
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement