iPhone SDK - UITextField with + Button for Contacts

爱⌒轻易说出口 提交于 2019-12-20 09:24:44

问题


In some applications like Mail, when you have a UITextField, there is a little + button to the right. When you tap it, a modal view controller comes up which you can select a phone number, address, etc from, and it will appear in the text field. I was wondering how to implement this in my own app. Thanks,
Isaac


回答1:


If you want the plus button inside the text field, take a look at the rightView property of the UITextField class, which lets you put any UIView in the right-most portion of the text field. You can put a UIButton there, as created with

[UIButton buttonWithType:UIButtonTypeContactAdd];



回答2:


You can do this by

txtFldObj.rightView = [UIButton buttonWithType:UIButtonTypeContactAdd];

txtFldObj.rightViewMode=UITextFieldViewModeAlways;

you can also refer to this trick also




回答3:


You can do this by having a regular UIView that contains a UITextField and a UIButton as subviews.

E.g

-------------------------------
| UITextField       | UIButton|
-------------------------------

When the button is tapped you can bring up the address book picker (or anything else) as a modal view, and when it closes update the text field as necessary.



来源:https://stackoverflow.com/questions/663830/iphone-sdk-uitextfield-with-button-for-contacts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!