0

I'm trying to design such a button or a textfield, but exactly how can I do it? This is my textfield. I added an arrow to the right.

@IBOutlet weak var pickerTextField: UITextField!{
    
    didSet {
        pickerTextField.tintColor = UIColor.lightGray
        pickerTextField.setIcon(#imageLiteral(resourceName: "drop-down-arrow"))
    }
    
}

extension UITextField {
    func setIcon(_ image: UIImage) {
        let iconView = UIImageView(frame:
        CGRect(x: -40, y: 7, width: 15, height: 15))
        iconView.image = image
        
        let iconContainerView: UIView = UIView(frame:
        CGRect(x: -50, y: 0, width: 30, height: 30))
        
        
        iconContainerView.addSubview(iconView)
        rightView = iconContainerView
        rightViewMode = .always
    }
}

enter image description here

enter image description here

aheze
  • 24,434
  • 8
  • 68
  • 125
cmszr
  • 59
  • 1
  • 9
  • 1
    What code have you tried so far? – aheze Dec 29 '20 at 18:14
  • I just added arrow to the right. I can change background color of container view. But then I need to round corners. Because its'a square so another problem is how can I just round right corners. – cmszr Dec 29 '20 at 18:22
  • For [only rounding the right corners](https://www.hackingwithswift.com/example-code/calayer/how-to-round-only-specific-corners-using-maskedcorners) you can do `yourRightView.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMaxXMaxYCorner]` – aheze Dec 29 '20 at 18:33
  • To have round corner this you can try out ...https://stackoverflow.com/questions/4847163/round-two-corners-in-uiview/45434170#45434170 – SachinVsSachin Dec 29 '20 at 18:39
  • Are you also looking for the dropdown implementation – Luca Sfragara Dec 29 '20 at 20:32
  • no just button design – cmszr Dec 29 '20 at 20:34
  • @cemsezeroglu Why would you add the UIImageView inside another view? Whats wrong with setting the UIImageView as your rightView? – Leo Dabus Dec 29 '20 at 23:05

0 Answers0