Advertisement
Guest User

custom

a guest
Jan 28th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 4.18 KB | None | 0 0
  1. //
  2. //  CustomKeybrd.swift
  3. //  MyInterfaceTemplates
  4. //
  5. //  Created by Константин Седлецкий on 28.01.2020.
  6. //  Copyright © 2020 Бизнес.ру. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class CustomKeybrd: UIView {
  12.     let buttonsArray1 = ["1", "2", "3"]
  13.     let buttonsArray2 = ["4", "5", "6"]
  14.     let buttonsArray3 = ["7", "8", "9"]
  15.     var buttons123 = [UIButton] ()
  16.     var buttons456 = [UIButton] ()
  17.     var buttons789 = [UIButton] ()
  18.    
  19.     func updateView() {
  20.         buttons123.removeAll()
  21.         buttons456.removeAll()
  22.         buttons789.removeAll()
  23.         subviews.forEach { (view) in
  24.             view.removeFromSuperview()
  25.         }
  26.        
  27.         for buttonTitle in buttonsArray1 {
  28.             let button = UIButton(type: .system)
  29.             let title = NSAttributedString(string: buttonTitle, attributes: [
  30.                 NSAttributedString.Key.foregroundColor: UIColor(red: 0.554, green: 0.587, blue: 0.638, alpha: 1),
  31.                 NSAttributedString.Key.font: UIFont.init(name: "ProximaNova-Regular", size: 40)!
  32.             ])
  33.             button.setAttributedTitle(title, for: .normal)
  34.             buttons123.append(button)
  35.         }
  36.        
  37.         for buttonTitle in buttonsArray2 {
  38.             let button = UIButton(type: .system)
  39.             let title = NSAttributedString(string: buttonTitle, attributes: [
  40.                 NSAttributedString.Key.foregroundColor: UIColor(red: 0.554, green: 0.587, blue: 0.638, alpha: 1),
  41.                 NSAttributedString.Key.font: UIFont.init(name: "ProximaNova-Regular", size: 40)!
  42.             ])
  43.             button.setAttributedTitle(title, for: .normal)
  44.             buttons456.append(button)
  45.         }
  46.        
  47.         for buttonTitle in buttonsArray3 {
  48.             let button = UIButton(type: .system)
  49.             let title = NSAttributedString(string: buttonTitle, attributes: [
  50.                 NSAttributedString.Key.foregroundColor: UIColor(red: 0.554, green: 0.587, blue: 0.638, alpha: 1),
  51.                 NSAttributedString.Key.font: UIFont.init(name: "ProximaNova-Regular", size: 40)!
  52.             ])
  53.             button.setAttributedTitle(title, for: .normal)
  54.             buttons789.append(button)
  55.         }
  56.        
  57.         let buttons123Stack = UIStackView(arrangedSubviews: buttons123)
  58.         buttons123Stack.translatesAutoresizingMaskIntoConstraints = false
  59.         buttons123Stack.axis = NSLayoutConstraint.Axis.horizontal
  60.         buttons123Stack.distribution = UIStackView.Distribution.equalSpacing
  61.         buttons123Stack.alignment = UIStackView.Alignment.center
  62.  
  63.         let buttons456Stack = UIStackView(arrangedSubviews: buttons456)
  64.         buttons456Stack.translatesAutoresizingMaskIntoConstraints = false
  65.         buttons456Stack.axis = NSLayoutConstraint.Axis.horizontal
  66.         buttons456Stack.distribution = UIStackView.Distribution.equalSpacing
  67.         buttons456Stack.alignment = UIStackView.Alignment.center
  68.        
  69.         let buttons789Stack = UIStackView(arrangedSubviews: buttons789)
  70.         buttons789Stack.translatesAutoresizingMaskIntoConstraints = false
  71.         buttons789Stack.axis  = NSLayoutConstraint.Axis.horizontal
  72.         buttons789Stack.distribution  = UIStackView.Distribution.equalSpacing
  73.         buttons789Stack.alignment = UIStackView.Alignment.center
  74.        
  75.         addSubview(buttons123Stack)
  76.         addSubview(buttons456Stack)
  77.         addSubview(buttons789Stack)
  78.  
  79.         buttons123Stack.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
  80.         buttons123Stack.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
  81.  
  82.         buttons456Stack.topAnchor.constraint(equalTo: buttons123Stack.bottomAnchor).isActive = true
  83.         buttons456Stack.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
  84.         buttons456Stack.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
  85.  
  86.         buttons789Stack.topAnchor.constraint(equalTo: buttons456Stack.bottomAnchor).isActive = true
  87.         buttons789Stack.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
  88.         buttons789Stack.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
  89.     }
  90.    
  91.     override func draw(_ rect: CGRect) {
  92.         updateView()
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement