52 lines
1.8 KiB
Swift
52 lines
1.8 KiB
Swift
//
|
|
// TextFieldImage.swift
|
|
// WOKA
|
|
//
|
|
// Created by MacBook Pro on 29/04/24.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension UITextField {
|
|
|
|
//MARK:- Set Image on the right of text fields
|
|
|
|
func setupRightImage(imageName:String,tintColor : UIColor?){
|
|
let imageView = UIImageView(frame: CGRect(x: 10, y: 10, width: 20, height: 20))
|
|
imageView.image = UIImage(named: imageName)
|
|
let imageContainerView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 55, height: 40))
|
|
imageContainerView.addSubview(imageView)
|
|
rightView = imageContainerView
|
|
rightViewMode = .always
|
|
self.tintColor = tintColor ?? .lightGray
|
|
}
|
|
|
|
//MARK:- Set Image on left of text fields
|
|
|
|
func setupLeftImage(imageName:String,tintColor : UIColor?){
|
|
let imageView = UIImageView(frame: CGRect(x: 10, y: 10, width: 20, height: 20))
|
|
imageView.image = UIImage(named: imageName)
|
|
let imageContainerView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 55, height: 40))
|
|
imageContainerView.addSubview(imageView)
|
|
leftView = imageContainerView
|
|
leftViewMode = .always
|
|
self.tintColor = tintColor ?? .lightGray
|
|
}
|
|
}
|
|
|
|
|
|
extension UITextField {
|
|
func addRightButton(title: String?, tintColor : UIColor, btnImage : UIImage?, target: Any?, action: Selector) {
|
|
// Create a button
|
|
let button = UIButton(type: .system)
|
|
button.setTitle(title, for: .normal)
|
|
button.addTarget(target, action: action, for: .touchUpInside)
|
|
button.setImage(btnImage, for: .normal)
|
|
button.tintColor = tintColor
|
|
button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10)
|
|
// Set the button as the right view of the text field
|
|
self.rightView = button
|
|
self.rightViewMode = .always
|
|
}
|
|
}
|