Skip to content

Instantly share code, notes, and snippets.

@perlguy99
Last active January 11, 2019 16:24
Show Gist options
  • Save perlguy99/feace8804be0bbf0cb08d666d71ddeab to your computer and use it in GitHub Desktop.
Save perlguy99/feace8804be0bbf0cb08d666d71ddeab to your computer and use it in GitHub Desktop.
//
// IconTitleTextView.swift
//
// Created by Brent Michalski on 12/23/18.
// Copyright © 2018 Perlguy, Inc. All rights reserved.
//
// THIS CUSTOM CLASS PROPERLY LOADS FROM A STORYBOARD!!!
import UIKit
import Font_Awesome_Swift
@IBDesignable
class CustomViewView: UIView {
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var icon: UIImageView!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var text: UILabel!
@IBInspectable var titleTextColor: UIColor {
get { return title.textColor }
set { title.textColor = newValue }
}
@IBInspectable var textTextColor: UIColor {
get { return text.textColor }
set { text.textColor = newValue }
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initNib()
}
override init(frame: CGRect) {
super.init(frame: frame)
initNib()
}
private func initNib() {
if !self.subviews.isEmpty { return }
let bundle = Bundle(for: CustomViewView.self)
bundle.loadNibNamed(String(describing: CustomViewView.self), owner: self, options: nil)
self.addSubview(self.containerView)
self.containerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
self.containerView.topAnchor.constraint(equalTo: self.topAnchor),
self.containerView.bottomAnchor.constraint(equalTo: self.bottomAnchor),
self.containerView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
self.containerView.trailingAnchor.constraint(equalTo: self.trailingAnchor)
])
clipsToBounds = true
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment