Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an UIButton inside an UITextField

I want to add a button with text "..." inside my UITextField. What i'm trying is the following:

@IBOutlet weak var requestTitleTxtField: UITextField!

viewDidLoad():

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

This is not returning any error message but isn't showing the button either.

like image 378
adolfosrs Avatar asked Sep 07 '15 17:09

adolfosrs


1 Answers

Create the button with frame:

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 color for the text:

detailsButton.setTitleColor(UIColor.redColor(), forState: .Normal)
like image 115
MirekE Avatar answered Nov 09 '22 21:11

MirekE