Skip to content

Instantly share code, notes, and snippets.

@Oni-zerone
Last active August 22, 2017 08:22
Show Gist options
  • Save Oni-zerone/82135951fc7e8d69781df5abf94c6284 to your computer and use it in GitHub Desktop.
Save Oni-zerone/82135951fc7e8d69781df5abf94c6284 to your computer and use it in GitHub Desktop.
SOTBubbleLabel
//
// SOTBubbleLabel.swift
//
//
// Created by Andrea Altea on 18/08/17.
// Copyright 2017 Andrea Altea. All rights reserved.
//
import UIKit
@IBDesignable class SOTBubbleLabel: UILabel {
override init(frame: CGRect) {
super.init(frame: frame)
self.setupUI()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupUI()
}
func setupUI() {
self.layoutMargins = UIEdgeInsetsMake(2, 8, 2, 8)
}
override func draw(_ rect: CGRect) {
self.layer.cornerRadius = min(rect.width, rect.height)/2
super.draw(rect)
}
override func drawText(in rect: CGRect) {
let textRect = CGRect(x: rect.origin.x + self.layoutMargins.right,
y: rect.origin.y,
width: rect.size.width - (self.layoutMargins.left + self.layoutMargins.right),
height: rect.size.height)
super.drawText(in: textRect)
}
override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
return CGSize(width: size.width + self.layoutMargins.left + self.layoutMargins.right,
height: size.height + self.layoutMargins.top + self.layoutMargins.bottom)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment