SHARE
TWEET

Untitled

a guest Sep 17th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CentralMenuButton: UIButton {
  2.     var label: UILabel?
  3.     var labelText: String!
  4.     var labelColor: UIColor!
  5.     var labelFont: UIFont!
  6.     var labelAlignment: NSTextAlignment!
  7.  
  8.     override init(frame: CGRect) {
  9.         super.init(frame: frame)
  10.         self.setupButton()
  11.     }
  12.  
  13.     func setupButton() {
  14.         self.layer.cornerRadius = 10
  15.         self.labelText = self.titleLabel?.text
  16.         self.labelColor = self.titleLabel?.textColor
  17.         self.labelAlignment = self.titleLabel?.textAlignment
  18.         self.labelFont = self.titleLabel?.font
  19.  
  20.         self.setTitle("", for: .normal)
  21.  
  22.         if self.labelText != nil {
  23.             self.setLabel(text: labelText)
  24.         }
  25.  
  26.     }
  27.  
  28.     func setLabel(text: String) {
  29.         if self.label == nil {
  30.             let frame = CGRect(x: 8, y: 8, width: self.frame.width, height: 35)
  31.             self.label = UILabel(frame: frame)
  32.             self.label?.font = self.labelFont
  33.             self.label?.textColor = self.labelColor
  34.             self.label?.textAlignment = self.labelAlignment
  35.             self.addSubview(label!)
  36.         }
  37.         label?.text = text
  38.     }
  39.     required init?(coder aDecoder: NSCoder) {
  40.         super.init(coder: aDecoder)
  41.         self.setupButton()
  42.     }
  43. }
  44.  
  45. class SecondaryMenuButton: UIButton {
  46.     var label: UILabel?
  47.     var labelText: String!
  48.     var labelColor: UIColor!
  49.     var labelFont: UIFont!
  50.     var labelAlignment: NSTextAlignment!
  51.  
  52.     override init(frame: CGRect) {
  53.         super.init(frame: frame)
  54.         self.setupButton()
  55.     }
  56.  
  57.     func setupButton() {
  58.         self.layer.cornerRadius = 10
  59.         self.labelText = self.titleLabel?.text
  60.         self.labelColor = self.titleLabel?.textColor
  61.         self.labelAlignment = self.titleLabel?.textAlignment
  62.         self.labelFont = self.titleLabel?.font
  63.  
  64.         self.setTitle("", for: .normal)
  65.  
  66.         if self.labelText != nil {
  67.             self.setLabel(text: labelText)
  68.         }
  69.  
  70.     }
  71.  
  72.     func setTextColor(color: UIColor) {
  73.         setupLabel()
  74.         label?.textColor = color
  75.     }
  76.  
  77.     func setTextAlignment(alignment: NSTextAlignment) {
  78.         setupLabel()
  79.         label?.textAlignment = alignment
  80.     }
  81.  
  82.     private func setupLabel() {
  83.         if self.label == nil {
  84.             let frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)
  85.             self.label = UILabel(frame: frame)
  86.             self.label?.font = self.labelFont
  87.             self.label?.textColor = self.labelColor
  88.             self.label?.textAlignment = self.labelAlignment
  89.             self.addSubview(label!)
  90.         }
  91.     }
  92.  
  93.     func setLabel(text: String) {
  94.         setupLabel()
  95.         label?.text = text
  96.     }
  97.     required init?(coder aDecoder: NSCoder) {
  98.         super.init(coder: aDecoder)
  99.         self.setupButton()
  100.     }
  101. }
  102.  
  103. class BasicRoundedButton: UIButton {
  104.     override init(frame: CGRect) {
  105.         super.init(frame: frame)
  106.         self.setupButton()
  107.     }
  108.     required init?(coder aDecoder: NSCoder) {
  109.         super.init(coder: aDecoder)
  110.         self.setupButton()
  111.     }
  112.     func setupButton() {
  113.         self.layer.cornerRadius = 10
  114.     }
  115. }
  116.  
  117. class BasicRoundedSwitch: UIButton {
  118.     var statusLabel: UILabel?
  119.     var label: UILabel?
  120.     var labelText: String!
  121.     var labelColor: UIColor!
  122.     var labelFont: UIFont!
  123.     var labelAlignment: NSTextAlignment!
  124.    
  125.     @IBInspectable var onColor: UIColor = UIColor.green
  126.     @IBInspectable var offColor: UIColor = UIColor.red
  127.     @IBInspectable var offLabelText: String = "Off"
  128.     @IBInspectable var onLabelText: String = "On"
  129.     @IBInspectable var switchState: Bool = false {
  130.         didSet {
  131.             self.updateLabel()
  132.         }
  133.     }
  134.  
  135.     func updateLabel() {
  136.         if switchState == false {
  137.             self.statusLabel?.text = self.offLabelText
  138.             self.updateBackgroundColor(color: self.offColor)
  139.         } else {
  140.             self.statusLabel?.text = self.onLabelText
  141.             self.updateBackgroundColor(color: self.onColor)
  142.         }
  143.     }
  144.    
  145.     private func updateBackgroundColor(color: UIColor){
  146.         UIView.animate(withDuration: 0.3) {
  147.             self.backgroundColor = color
  148.         }
  149.     }
  150.    
  151.     private func setupLabel() {
  152.         if self.statusLabel == nil {
  153.             let frame = CGRect(x: 8, y: 38, width: self.frame.width, height: 30)
  154.             statusLabel = UILabel.init(frame: frame)
  155.             statusLabel?.textColor = self.labelColor
  156.             statusLabel?.font = UIFont.systemFont(ofSize: 25)
  157.             self.updateLabel()
  158.             self.addSubview(statusLabel!)
  159.         }
  160.         if self.label == nil {
  161.             let frame = CGRect(x: 8, y: 8, width: self.frame.width, height: 30)
  162.             label = UILabel(frame: frame)
  163.             label?.font = self.labelFont
  164.             label?.preferredMaxLayoutWidth = self.frame.width
  165.             label?.textColor = self.labelColor
  166.             label?.textAlignment = self.labelAlignment
  167.             label?.numberOfLines = 0
  168.             label?.lineBreakMode = .byWordWrapping
  169.             let widthConstraint = NSLayoutConstraint(item: label!, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 1, constant: 0)
  170.             self.addConstraint(widthConstraint)
  171.            
  172.             self.addSubview(label!)
  173.         }
  174.     }
  175.  
  176.     override init(frame: CGRect) {
  177.         super.init(frame: frame)
  178.         self.setupButton()
  179.     }
  180.     required init?(coder aDecoder: NSCoder) {
  181.         super.init(coder: aDecoder)
  182.         self.setupButton()
  183.     }
  184.  
  185.     @objc func toggled() {
  186.         if self.switchState == false {
  187.             self.switchState = true
  188.         } else {
  189.             self.switchState = false
  190.         }
  191.         self.updateLabel()
  192.     }
  193.  
  194.     func setLabel(text: String) {
  195.         setupLabel()
  196.         label?.text = text
  197.     }
  198.  
  199.     func setupButton() {
  200.         self.labelText = self.titleLabel?.text
  201.         self.labelColor = self.titleLabel?.textColor
  202.         self.labelAlignment = self.titleLabel?.textAlignment
  203.         self.labelFont = self.titleLabel?.font
  204.         self.layer.cornerRadius = 10
  205.         self.setupLabel()
  206.         self.setTitle("", for: .normal)
  207.  
  208.         if self.labelText != nil {
  209.             self.setLabel(text: labelText)
  210.         }
  211.         self.addTarget(self, action: #selector(toggled), for: .touchDown)
  212.     }
  213. }
  214.  
  215. class CentralMenuContainerView: UIView {
  216.     override init(frame: CGRect) {
  217.         super.init(frame: frame)
  218.         self.layer.cornerRadius = 10
  219.     }
  220.  
  221.     required init?(coder aDecoder: NSCoder) {
  222.         super.init(coder: aDecoder)
  223.         self.layer.cornerRadius = 10
  224.     }
  225. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top