I currently have a standard NSSearchField
(in a nib). The height is fixed by Apple at 22px. The application supports or uses Tibetan Unicode. Tibetan characters are written left to right, but certain adjacent characters stack vertically which makes for an unusually large line height. Text entered into the search field is clipped. My solution is to subclass NSSearchFieldCell
and if necessarily NSSearchField
.
First problem: It's hard to figure out what methods to override. I find hints in the Apple documentation but nothing systematic. Any pointers are appreciated.
What I have so far: I subclassed NSSearchFieldCell
. I replaced searchTextRectForBounds
, cancelButtonRectForBounds
, searchButtonRectForBounds
, and finally drawWithFrame inView
.
I get a decent graphical image at the desired size. The cancel button is drawn in the expected location, but I have no idea where the cancel button controls are on the screen.
What other methods to I need to override?
To illustrate the problem, the following text ཀླུའི་རྒྱལ་པོ་
transliterated into Latin/Roman letters klu'i rgyal po in the search bar used by Finder. Notice the gigu "U" is clipped along the bottom.
I wouldn't go down that road at all. Instead you should subclass NSView and stick an NSTextField + NSPopUpButton + NSButton inside it.
With a bunch of hacking you'll get it working but then OS X 10.10 will ship and it will be broken.
You need to make a custom NSSearchFieldCell subclass, and override drawWithFrame:, then set your NSSearchField to use that cell. You can either draw your custom border in code, or use end-cap images and a background image for the center that you tile horizontally. (I Haven't tried this)
Try that out.
Alternatively, just create a NSTextFeild, then update the view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With