PDA

View Full Version : How To Add Buttons Inside Text Field?




Blakeasd
Oct 25, 2010, 02:56 PM
Hello,
How can I add buttons inside a text field. I first tried to do this by dropping a button onto the text field. This worked fine, but text under it was not visible. How can I add a button in a text field like in Apple's Safari, if text is very long it doesn't go under the buttons. How can I achieve this?
Thanks



jared_kipe
Oct 25, 2010, 03:23 PM
well to be perfectly honest, you can't read the text behind apple's buttons either. They make a white gradient that obscures text behind the button. So I'd say the easiest thing to do would be to make your own gradient, put that in the text bar and then put the button over it.

Other options that would probably work (I really only develop on the iPhone) would be subclass NSTextFieldCell or NSTextField itself. Or figure out how it determines where to stop the text and start moving it off to the left side and add a Category to NSTextField that allows you to set that property on regular NSTextFields.

Blakeasd
Oct 25, 2010, 03:51 PM
Wirelessly posted (Mozilla/5.0 (iPod; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7)

I figured it out. I used a custom view to draw a box that looked like a text field and put it by the real text field. Then I took a button and put inside my fake text field. It was a complicated way of doing things but it worked.

jared_kipe
Oct 25, 2010, 06:45 PM
How did you get it to do the highlighting?

Blakeasd
Oct 27, 2010, 07:10 AM
My fake text fields mouseDown method drew a blue border.

jared_kipe
Oct 27, 2010, 08:57 AM
Well I meant the blue border that selects the text box. Did you somehow receive the textField's mouse events?

Sydde
Oct 27, 2010, 12:27 PM
NSTextField does have a method -setDrawsBackground:

You could drop the cell on top of the button and give the field a transparent background.