60 lines
1.6 KiB
Swift
60 lines
1.6 KiB
Swift
//
|
|
// Object.swift
|
|
// List
|
|
//
|
|
// Created by admin on 6/16/20.
|
|
// Copyright © 2020 Extyl. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
@IBDesignable
|
|
class CommonTextField1: UITextField {
|
|
|
|
override var frame: CGRect {
|
|
didSet {
|
|
backgroundColor = UIColor(red: 0.969, green: 0.976, blue: 0.996, alpha: 1)
|
|
layer.cornerRadius = frameHeight/2
|
|
clipsToBounds = true
|
|
borderStyle = .none
|
|
}
|
|
}
|
|
|
|
var padding: UIEdgeInsets {
|
|
.init(top: 6, left: leftView == nil ? 16 : 32, bottom: 6, right: rightView == nil ? 16 : 32)
|
|
}
|
|
|
|
override open func textRect(forBounds bounds: CGRect) -> CGRect {
|
|
bounds.inset(by: padding)
|
|
}
|
|
|
|
override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
|
|
bounds.inset(by: padding)
|
|
}
|
|
|
|
override open func editingRect(forBounds bounds: CGRect) -> CGRect {
|
|
bounds.inset(by: padding)
|
|
}
|
|
|
|
override func rightViewRect(forBounds bounds: CGRect) -> CGRect {
|
|
guard let view = rightView else { return .zero }
|
|
return .init(
|
|
x: frameWidth - view.frameWidth - 12,
|
|
y: (frameHeight - view.frameHeight)/2,
|
|
width: view.frameWidth,
|
|
height: view.frameHeight
|
|
)
|
|
}
|
|
|
|
override func leftViewRect(forBounds bounds: CGRect) -> CGRect {
|
|
guard let view = leftView else { return .zero }
|
|
return .init(
|
|
x: (32 - view.frameWidth)/2,
|
|
y: (frameHeight - view.frameHeight)/2,
|
|
width: view.frameWidth,
|
|
height: view.frameHeight
|
|
)
|
|
}
|
|
|
|
}
|