自定义UITextField/ui按钮

What I'm trying to do is replicate the NSTokenField like UITextField seen in the Mail app and Messages app (type a contact and it comes up with suggestions).

I've got the autocompleting working perfectly, when you type in a UITextField, a UITableView pops up showing any matches that it can find in an array, when you click one it adds it to the UITextField. I'm really happy with this so far.

The problem I've run into now is making the controls look like those in the native apps. Afterall, design is everything!

My first question is how can I add that shadow look to the UITableView? Looks like it's sunk down behind the UITextField.

Secondly, I know I'm going to have to subclass the UITextField to make it look the way I'd like it to, but I've got no idea where to start with that. Some pointers or a sample would be great!

Lastly, I think I need to create a custom UIButton with space for text and the blue gradient then add it to the UITextField. Same problem as with the UITextField, not really sure how to subclass the UIButton (what methods it needs to draw and stuff) or how to add it to the UITextField in such a way that when you click backspace on in the UITextField, the button will be highlighted, then deleted if backspace is clicked again (exactly how the NSTokenField works).

I've included an image just so you can see what I'm talking about: http://www.thermoglobalnuclearwar.com/stuff/mail.jpg

I have taken a look at Joe Hewitts Three20 project but I couldn't make heads or tails of it. I'd like to start very simply and understand everything that's going on rather than just dragging his code into mine and not having any idea what's going on!

Any help is greatly appreciated!

Thanks, Tom.

#0

Okay, I've got the shadow working underneath the UITextField, and I've added the "To:" label to it. It looks great!

So the final thing is the blue NSToken like control. I've started to think the easiest thing is just to subclass a UIView and draw the blue gradient and label inside it. Which brings me to some more questions:

I found this: http://github.com/leonho/iphone-libs/tree/master which draws a nice rounded view and I've adapted it to add some text to it rather than a number, what I don't know how to do is draw a gradient instead of a solid block of colour.

After that there's just the matter of adding the rounded views to the UITextField, moving the cursor and working out how to delete the views when the cursor reaches them, but I'll tackle that when I need to.

#1

Have you considered using the Three20 library? It contains a control which I think does what you want (TTPickerTextView).

As the website description states

TTPickerTextField is a type-ahead UITextField. As you type it searches a data source, and it adds bubbles into the flow of text when you choose a type-ahead option. I use this in TTMessageController for selecting the names of message recipients.

At a minimum the source code might give you some pointers on how to achieve the various visual effects.

推荐文章

iPhone3GS越狱升级至4.0版本

iPhone3GS越狱升级至4.0版本

推荐文章

备份非常大的MySQL数据库

备份非常大的MySQL数据库

推荐文章

在我的应用程序中移动到另一页的正确方式

在我的应用程序中移动到另一页的正确方式

推荐文章

cakephp应用程序中缺少验证消息

cakephp应用程序中缺少验证消息

推荐文章

是HTML 5+CSS 3>=Microsoft Silverlight

是HTML 5+CSS 3>=Microsoft Silverlight

推荐文章

pysqlite-如何保存图像

pysqlite-如何保存图像

推荐文章

从JDBC数据源将数据泵入ActiveMQ

从JDBC数据源将数据泵入ActiveMQ

推荐文章

如何在加载在多页编辑器中的Java编辑器中启用“标记引用”?

如何在加载在多页编辑器中的Java编辑器中启用“标记引用”?

推荐文章

在运行时查找新的Java类

在运行时查找新的Java类

推荐文章

“path”不是Image.source的有效属性

“path”不是Image.source的有效属性

推荐文章

在NFS上使用couchdb

在NFS上使用couchdb

推荐文章

批处理脚本命令在变量名中添加/更改编号

批处理脚本命令在变量名中添加/更改编号

推荐文章

Silverlight数据绑定,避免缺少属性时出现BindingExpression路径错误,而是隐藏控件

Silverlight数据绑定,避免缺少属性时出现BindingExpression路径错误,而是隐藏控件

推荐文章

在Linux上增加文件要花多少钱?

在Linux上增加文件要花多少钱?

推荐文章

System.ServiceModel消失

System.ServiceModel消失

推荐文章

Java HTMLUnit-提交表单后如何访问发送到的do m页面

Java HTMLUnit-提交表单后如何访问发送到的do m页面