'How to add space and resize image for rightView of UITextField
I need to make this kind of text fields but I don't know how can I make spacing for rightView.
Here is a code where I'm trying to set rightView image
let imageView = UIImageView(frame: CGRect(x: -10, y: -10, width: 22, height: 22))
imageView.image = UIImage(systemName: systemName)
self.rightView = imageView
self.rightViewMode = .always
I've tried to play around CGRect coordinates and size but my rightView looks same every time
Here is how my UITextField looks now
Solution 1:[1]
Try using
parentView.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 8)
on parent
textview.
Solution 2:[2]
` public override func rightViewRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(x: bounds.width - 30, y: 0, width: 30 , height: bounds.height)
}`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Muhtasim Ulfat Tanmoy |
Solution 2 | Rapkat Baudunov |