Adding UIButton inside UITextField

I want to add a button with the text "..." inside my UITextField. I am trying to do the following:

@IBOutlet weak var requestTitleTxtField: UITextField!

viewDidLoad ():

var detailsButton = UIButton()
detailsButton.titleLabel!.text = "..."
requestTitleTxtField.rightViewMode = UITextFieldViewMode.Always
requestTitleTxtField.rightView = detailsButton

This does not return an error message, but also does not show a button.

+4
source share
1 answer

Create a button with a border:

var detailsButton = UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24))

Use detailsButton.setTitle("...", forState: .Normal)to set the title.

You may also need to set a color for the text:

detailsButton.setTitleColor(UIColor.redColor(), forState: .Normal)
+5
source

Source: https://habr.com/ru/post/1606293/


All Articles