"uitextfield add image icon right" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "uitextfield add image icon right" answered properly. Developers are finding an appropriate answer about uitextfield add image icon right related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like uitextfield add image icon right. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on uitextfield add image icon right.
uitextfield add image icon right
Swift 5
//MARK: - CustomTextView
class BaseTextField: UITextField {
var setHPad: UIEdgeInsets = { return UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 8 ) }()
override open func textRect( forBounds bounds: CGRect ) -> CGRect {
return bounds.inset( by: self.setHPad )
}
override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return bounds.inset(by: self.setHPad )
}
override open func editingRect(forBounds bounds: CGRect) -> CGRect {
return bounds.inset(by: self.setHPad )
}
@IBInspectable open var leftImage:String? {
didSet {
if (leftImage != nil) {
self.applyLeftImage(leftImage!)
self.setHPad = { return UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 30 ) }()
}
}
}
fileprivate func applyLeftImage(_ image: String) {
// set image
let imageView = UIImageView()
imageView.image = UIImage( systemName: image )
imageView.tintColor = UIColor(named: K.EpColors.black)
imageView.clipsToBounds = true
// set holder
let viewHolder = UIView()
viewHolder.clipsToBounds = true
viewHolder.addSubview(imageView)
// prepare for constraints
imageView.translatesAutoresizingMaskIntoConstraints = false
viewHolder.translatesAutoresizingMaskIntoConstraints = false
// views param
let viewsDictionary = [
"imageHolder": viewHolder,
"image":imageView
]
let metrics = [
"default": 8,
"none": 0
]
// set horisontal constraints
viewHolder.addConstraints(
NSLayoutConstraint.constraints(withVisualFormat: "H:|-(default)-[image]-(default)-|",
options: [],
metrics: metrics,
views: viewsDictionary))
// set vertical constraints
viewHolder.addConstraints(
NSLayoutConstraint.constraints(withVisualFormat: "V:|-(default)-[image]-(default)-|",
options: [],
metrics: metrics,
views: viewsDictionary))
// add image to textfield
self.addSubview(viewHolder)
// keep childView from overflowing
self.clipsToBounds = true
// set horizontal constraints
self.addConstraints(
NSLayoutConstraint.constraints(withVisualFormat: "H:|-(>=default)-[imageHolder]-(none)-|",
options: [],
metrics: metrics,
views: viewsDictionary)
)
// set vertical constraints
self.addConstraints(
NSLayoutConstraint.constraints(withVisualFormat: "V:|-(none)-[imageHolder]-(none)-|",
options: [],
metrics: metrics,
views: viewsDictionary)
)
self.rightView?.tintColor = UIColor( named: K.EpColors.black )
}
}
All those coders who are working on the Whatever based application and are stuck on uitextfield add image icon right can get a collection of related answers to their query. Programmers need to enter their query on uitextfield add image icon right related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about uitextfield add image icon right for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of uitextfield add image icon right while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "uitextfield add image icon right". Visit this developer's friendly online web community, CodeProZone, and get your queries like uitextfield add image icon right resolved professionally and stay updated to the latest Whatever updates.