Skip to content

Instantly share code, notes, and snippets.

@damodarnamala
Created May 22, 2018 05:27
Show Gist options
  • Save damodarnamala/0dfc1bcaa82433c6504f4b4cb821c8cd to your computer and use it in GitHub Desktop.
Save damodarnamala/0dfc1bcaa82433c6504f4b4cb821c8cd to your computer and use it in GitHub Desktop.
IOS Theme UI Eelements
import UIKit
@IBDesignable
class TextField: UITextField {
enum ImageDirection {
case left
case right
}
@IBInspectable var sholdShowRightView : Int = 0 {
didSet {
if sholdShowRightView == 1 {
self.setImageDirection(direction: .right)
}
}
}
@IBInspectable var sholdShowLeftView : Int = 0 {
didSet {
if sholdShowLeftView == 1 {
self.setImageDirection(direction: .left)
}
}
}
@IBInspectable var showBorder : Int = 0 {
didSet {
if sholdShowLeftView == 1 {
self.layer.borderColor = UIColor.lightGray.cgColor
self.layer.borderWidth = 1
}
}
}
func setImageDirection(direction: ImageDirection) {
switch direction {
case .left:
self.leftView = UIImageView(image: UIImage(named: "left"))
self.leftViewMode = .always
case .right:
self.rightView = UIImageView(image: UIImage(named: "right"))
self.rightViewMode = .always
}
}
}
import UIKit
enum LabelType : Int {
case small
case normal
case bold
case heading
}
@IBDesignable
class Label: UILabel {
var displayType : LabelType = .normal
@IBInspectable var labelDisplayType : Int {
get {
return self.displayType.rawValue
}
set( index) {
self.displayType = LabelType(rawValue: index)!
self.setLabelType(type: self.displayType)
}
}
func setLabelType(type: LabelType) {
switch type {
case .small:
self.font = UIFont.init(name: "Arial", size: 12)
self.textColor = UIColor.gray.withAlphaComponent(0.75)
case .normal:
self.font = UIFont.init(name: "Arial", size: 14)
self.textColor = UIColor.darkGray
case .bold:
self.font = UIFont.init(name: "Arial", size: 14)
self.textColor = UIColor.red.withAlphaComponent(1)
case .heading:
self.font = UIFont.init(name: "Helvetica-Bold", size: 16)
self.textColor = UIColor.purple.withAlphaComponent(1)
}
}
}
import UIKit
@IBDesignable
class TextField: UITextField {
enum ImageDirection {
case left
case right
}
@IBInspectable var sholdShowRightView : Int = 0 {
didSet {
if sholdShowRightView == 1 {
self.setImageDirection(direction: .right)
}
}
}
@IBInspectable var sholdShowLeftView : Int = 0 {
didSet {
if sholdShowLeftView == 1 {
self.setImageDirection(direction: .left)
}
}
}
@IBInspectable var showBorder : Int = 0 {
didSet {
if sholdShowLeftView == 1 {
self.layer.borderColor = UIColor.lightGray.cgColor
self.layer.borderWidth = 1
}
}
}
func setImageDirection(direction: ImageDirection) {
switch direction {
case .left:
self.leftView = UIImageView(image: UIImage(named: "left"))
self.leftViewMode = .always
case .right:
self.rightView = UIImageView(image: UIImage(named: "right"))
self.rightViewMode = .always
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment