Advertisement
rex897

textField

Jan 14th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.11 KB | None | 0 0
  1. //
  2. //  CustomTextField.swift
  3. //  MyInterfaceTemplates
  4. //
  5. //  Created by Константин Седлецкий on 10.01.2020.
  6. //  Copyright © 2020 Бизнес.ру. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class CustomTextField: UITextField {
  12.    
  13.     let insets: UIEdgeInsets
  14.    
  15.     init(insets: UIEdgeInsets){
  16.         self.insets = insets
  17.         super.init(frame: .zero)
  18.         self.layer.borderWidth = 1
  19.         self.layer.cornerRadius = 5
  20.         self.translatesAutoresizingMaskIntoConstraints = false
  21.         self.heightAnchor.constraint(equalToConstant: 56).isActive = true
  22.         self.keyboardType = .numberPad
  23.         self.textColor = UIColor.white
  24.         self.font = UIFont.init(name: "ProximaNova-Regular", size: 16)
  25.         self.attributedPlaceholder = NSAttributedString(string: "", attributes: [
  26.         .foregroundColor: UIColor.init(red: 141/255, green: 155/255, blue: 163/255, alpha: 0.5)
  27.         ])
  28.     }
  29.    
  30.     required init?(coder: NSCoder) {
  31.         fatalError("init(coder:) has not been implemented")
  32.     }
  33.    
  34.     override func textRect(forBounds bounds: CGRect) -> CGRect {
  35.         return bounds.inset(by: insets)
  36.     }
  37.    
  38.     override func editingRect(forBounds bounds: CGRect) -> CGRect {
  39.         return bounds.inset(by: insets)
  40.     }
  41.    
  42.     func setCornerRadius(cornerRadius: CGFloat) {
  43.         self.layer.cornerRadius = cornerRadius
  44.     }
  45.    
  46.     func setHeightAnchor(heightAnchor: CGFloat) {
  47.         self.heightAnchor.constraint(equalToConstant: heightAnchor).isActive = true
  48.     }
  49.    
  50.     func setBorderWidth(borderWidth: CGFloat) {
  51.         self.layer.borderWidth = borderWidth
  52.     }
  53.    
  54.     func setBorderColor(borderColor: UIColor) {
  55.         self.layer.borderColor = borderColor.cgColor
  56.     }
  57.    
  58.     func setAttributedPlaceholder(attributedPlaceholder: NSAttributedString) {
  59.         self.attributedPlaceholder = attributedPlaceholder
  60.     }
  61.    
  62.     func setKeyboardType(keyboardType: UIKeyboardType) {
  63.         self.keyboardType = keyboardType
  64.     }
  65.    
  66.     func setTextColor(textColor: UIColor) {
  67.         self.textColor = textColor
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement