Aditya Pandey
Aditya Pandey

Reputation: 15

Create UITextfield With Both Text and Placeholder

enter image description here

I want to create a UITextField like above image, with both placeholder in left side and name and Text in right side. Can someone please tell me how to do this.

Upvotes: 0

Views: 117

Answers (2)

Mahendra
Mahendra

Reputation: 8914

You can set this by setting leftView to the UITextFiled

You may declared var of IBOutlet for textfield.

let textField = UITextField()

or

@IBOutlet weak var textFiled: UITextFiled!


//create label
let lblName = UILabel(frame: CGRect(x: 0, y:0, width: 80, height: 30))
// --- set other properties to label 

//set right view to text field
textField.leftView = lblName
textField.leftView wMode = .whileEditing

You can change leftViewMode of the textField.

Upvotes: 1

Arnab
Arnab

Reputation: 4356

Try this:
Use a background view, inside that take a label and a textfield placed horizontally.

enter image description here

Make sure textField borderStyle is none and alignment right.

enter image description here

Output:

enter image description here

Upvotes: 1

Related Questions