简体   繁体   中英

Create UITextfield With Both Text and Placeholder

在此处输入图片说明

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.

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

在此处输入图片说明

Make sure textField borderStyle is none and alignment right.

在此处输入图片说明

Output:

在此处输入图片说明

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM