开发者

How do I create an NSSearchField programmatically?

I'm trying to create an NSSearchField programmatically; however, I don't know how to find the frame height of a standard NSSearchField (a la those in Interface Builder.) Obviously, I could simply copy the height from an NSSearchField entity in IB and call NSMakeFrame with that height, but that feels hackish - what happens when Apple changes the height of a typical search field? I'd rather the height not be hardcoded into my application. This is more of a "best practices开发者_开发问答" question, not an "I can't get it to work at all" one.

Thanks!


The magic method for this is

[mysearchfield sizeToFit]

which changes the frame to the minimum width and height. I use this in a Cocoa language wrapping where applications have to build their GUI completely without IB and it works on almost any NSControl class except for same cases (like small control size and NSComboBox) and for giving the width of icon only NSPopUpButton.

Also look at the Human Interface Guid of Apple. The pixel sizes are fixed so there is no danger in using magic pixel constants.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜