Xcode style font set

I want to add a selection of fonts to my application. Xcode Interface Builder has an excellent implementation, which is also used in the Xcode custom settings window.

This is the one with a small "T" button (apparently) inside the font name text box itself.

Is this a standard cocoa implementation?

+4
source share
2 answers

You need to roll on your own. See NSControl Subclass . You will be subclassed by NSTextField and NSTextFieldCell. In fact, read the entire guide. Once you have a good understanding, you can redefine the drawing / geometry procedures to return a rectangle whose width is slightly smaller (small enough to leave room for the "button" font). Then draw a font button. You will respond to mouse events on the font button in the same way as for any NSView.

0
source

There is no standard button preview text box control, but there is a standard NSFontPanel class that you can use to let users select a font after pressing the "T" button.

The best idea is probably to override NSTextFieldCell. I was able to get the desired look by overriding -drawInteriorWithFrame: inView :, and skipping a slightly wider frame when called in super, and then drawing the button myself. You will also need to do your own mouse button search, but you could just create your own instance of NSButtonCell and access it for several methods with sub-correction for the button.

For convenience, you can also create a subclass of NSTextField that uses this cell instead of the direct NSTextFieldCell, but if you are loading material from XIB, you can simply change the cell class in XIB and leave it as a plain text field.

0
source

Source: https://habr.com/ru/post/1399798/


All Articles