做法:
在storyboard放入一text field,接著在viewDidLoad事件中,建構一UIImageView object,並給予初始位置與大小,在assign給text field的leftView的property。例:
let imageTest = UIImageView(image: UIImage(named: "xxx.png"));
imageTest.bounds = CGRect(x: 0, y:0, width: 20, height: 20);
txtTest.leftViewMode = UITextFieldViewMode.Always;
txtTest.leftView = ImageTest;
參考資料:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/index.html
http://stackoverflow.com/questions/13508836/add-image-to-uitextfield-in-xcode
沒有留言:
張貼留言