電子郵件圖標和佔位符文本相互擁抱。如何設置在UITextField中添加的圖標的位置?
我想在它們之間添加一些空間。
下面是我使用創建這些字段的代碼。
// view for fields background
var view = UIView(frame: CGRectMake(35, 300, 300, 90));
view.backgroundColor = UIColor.whiteColor();
view.layer.cornerRadius = 5.0
// email text field
var email = UITextField(frame: CGRectMake(0, 0, 300, 50));
email.backgroundColor = UIColor.whiteColor();
var emailIcon = UIImageView();
var emailIconImage = UIImage(named: "email_icon.png");
emailIcon.image = emailIconImage;
email.leftView = emailIcon;
email.leftViewMode = UITextFieldViewMode.Always
email.layer.cornerRadius=5.0;
email.attributedPlaceholder = NSAttributedString(string:"E-mail",
attributes:[NSForegroundColorAttributeName: UIColor.grayColor()])
emailIcon.frame = CGRect(x: 30, y: 15, width: 30, height: 20)
view.addSubview(emailIcon)
謝謝!
的可能重複[插圖文字爲UITextField?] (http://stackoverflow.com/questions/2694411/text-inset-for-uitextfield) – Larme