Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CustomKeybrd.swift
- // MyInterfaceTemplates
- //
- // Created by Константин Седлецкий on 28.01.2020.
- // Copyright © 2020 Бизнес.ру. All rights reserved.
- //
- import UIKit
- class CustomKeybrd: UIView {
- let buttonsArray1 = ["1", "2", "3"]
- let buttonsArray2 = ["4", "5", "6"]
- let buttonsArray3 = ["7", "8", "9"]
- var buttons123 = [UIButton] ()
- var buttons456 = [UIButton] ()
- var buttons789 = [UIButton] ()
- func updateView() {
- buttons123.removeAll()
- buttons456.removeAll()
- buttons789.removeAll()
- subviews.forEach { (view) in
- view.removeFromSuperview()
- }
- for buttonTitle in buttonsArray1 {
- let button = UIButton(type: .system)
- let title = NSAttributedString(string: buttonTitle, attributes: [
- NSAttributedString.Key.foregroundColor: UIColor(red: 0.554, green: 0.587, blue: 0.638, alpha: 1),
- NSAttributedString.Key.font: UIFont.init(name: "ProximaNova-Regular", size: 40)!
- ])
- button.setAttributedTitle(title, for: .normal)
- buttons123.append(button)
- }
- for buttonTitle in buttonsArray2 {
- let button = UIButton(type: .system)
- let title = NSAttributedString(string: buttonTitle, attributes: [
- NSAttributedString.Key.foregroundColor: UIColor(red: 0.554, green: 0.587, blue: 0.638, alpha: 1),
- NSAttributedString.Key.font: UIFont.init(name: "ProximaNova-Regular", size: 40)!
- ])
- button.setAttributedTitle(title, for: .normal)
- buttons456.append(button)
- }
- for buttonTitle in buttonsArray3 {
- let button = UIButton(type: .system)
- let title = NSAttributedString(string: buttonTitle, attributes: [
- NSAttributedString.Key.foregroundColor: UIColor(red: 0.554, green: 0.587, blue: 0.638, alpha: 1),
- NSAttributedString.Key.font: UIFont.init(name: "ProximaNova-Regular", size: 40)!
- ])
- button.setAttributedTitle(title, for: .normal)
- buttons789.append(button)
- }
- let buttons123Stack = UIStackView(arrangedSubviews: buttons123)
- buttons123Stack.translatesAutoresizingMaskIntoConstraints = false
- buttons123Stack.axis = NSLayoutConstraint.Axis.horizontal
- buttons123Stack.distribution = UIStackView.Distribution.equalSpacing
- buttons123Stack.alignment = UIStackView.Alignment.center
- let buttons456Stack = UIStackView(arrangedSubviews: buttons456)
- buttons456Stack.translatesAutoresizingMaskIntoConstraints = false
- buttons456Stack.axis = NSLayoutConstraint.Axis.horizontal
- buttons456Stack.distribution = UIStackView.Distribution.equalSpacing
- buttons456Stack.alignment = UIStackView.Alignment.center
- let buttons789Stack = UIStackView(arrangedSubviews: buttons789)
- buttons789Stack.translatesAutoresizingMaskIntoConstraints = false
- buttons789Stack.axis = NSLayoutConstraint.Axis.horizontal
- buttons789Stack.distribution = UIStackView.Distribution.equalSpacing
- buttons789Stack.alignment = UIStackView.Alignment.center
- addSubview(buttons123Stack)
- addSubview(buttons456Stack)
- addSubview(buttons789Stack)
- buttons123Stack.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
- buttons123Stack.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
- buttons456Stack.topAnchor.constraint(equalTo: buttons123Stack.bottomAnchor).isActive = true
- buttons456Stack.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
- buttons456Stack.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
- buttons789Stack.topAnchor.constraint(equalTo: buttons456Stack.bottomAnchor).isActive = true
- buttons789Stack.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
- buttons789Stack.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
- }
- override func draw(_ rect: CGRect) {
- updateView()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement