Skip to content

Instantly share code, notes, and snippets.

public extension UIButton {
func styleText(font: UIFont, color: UIColor) -> UIButton {
return self <== {
$0.titleLabel?.font = font
$0.setTitleColor(color, for: .normal)
}
}
func styleBase() -> UIButton {
let firstName = UILabel().styleText(font: .regular(size: 12), color: .white)
let lastName = UILabel().styleText(font: .regular(size: 12), color: .white)
public extension UILabel {
func styleText(font: UIFont, color: UIColor, alignment: NSTextAlignment = .left) -> UILabel {
return self <== {
$0.font = font
$0.textColor = color
$0.textAlignment = alignment
}
}
func wrapLines(max: Int = 0) -> UILabel {
let firstName = UILabel() <== {
$0.font = .regular(size: 12)
$0.color = .white
}
let lastName = UILabel() <== {
$0.font = .regular(size: 12)
$0.color = .white
}
public extension UIFont {
static func bold(size: CGFloat) -> UIFont {
return UIFont(name: "AvenirNext-Bold", size: size)!
}
static func medium(size: CGFloat) -> UIFont {
return UIFont(name: "AvenirNext-Medium", size: size)!
}
static func regular(size: CGFloat) -> UIFont {
let firstName = UILabel() <== {
$0.font = UIFont(name: "AvenirNext-Regular", size: 12)!
$0.color = .white
}
let lastName = UILabel() <== {
$0.font = UIFont(name: "AvenirNext-Regular", size: 12)!
$0.color = .white
}
extension UITableView {
public func register(_ cellClass: Swift.AnyClass) {
self.register(cellClass, forCellReuseIdentifier: String(describing: cellClass))
}
public func dequeueReusableCell<T: UITableViewCell>() -> T {
return self.dequeueReusableCell(withIdentifier: String(describing: T.self)) as! T
}
}
// Before
let v1 = UIViewController()
v1.title = "View 1"
let v2 = UIViewController()
v2.title = "View 2"
let tabBar = UITabBarController(viewControllers: [v1, v2])
//After
class MyView: UIView {
let tableView = UITableView(frame: .zero, style: .plain) <== {
$0.backgroundColor = .clear
$0.separatorStyle = .none
$0.contentInset = UIEdgeInsets(top: 15, left: 0, bottom: 15, right: 0)
$0.register(TableCell.self, forCellReuseIdentifier: "TableCell")
}
let textField = UITextField() <== {
class MyView: UIView {
let tableView: UITableView
let textField: UITextField
let button: UIButton
init() {
tableView = UITableView(frame: .zero, style: .plain) <== {
$0.backgroundColor = .clear