How To Add Buttons Inside Text Field?

Discussion in 'Mac Programming' started by Blakeasd, Oct 25, 2010.

  1. macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    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
     
  2. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    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.
     
  3. thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #3
    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.
     
  4. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #4
    How did you get it to do the highlighting?
     
  5. thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #5
    My fake text fields mouseDown method drew a blue border.
     
  6. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #6
    Well I meant the blue border that selects the text box. Did you somehow receive the textField's mouse events?
     
  7. macrumors 68000

    Sydde

    Joined:
    Aug 17, 2009
    #7
    NSTextField does have a method -setDrawsBackground:

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

Share This Page