NSButton Gradient Style

In Interface Builder components, I have a Gradient button

Gradient Button

I would like to create this button programmatically. But I cannot find a combination of button type, border style and gradient type to reproduce it. My local goal is to create plus (add) and minus (delete) buttons like this

Add and remove items, gradient button

Maybe you also know how to implement the part to the right of the minus? It looks like a button with a gradient disabled.

Update (2012-02-01, 14:52)

I put the gradient button on an empty xib, open xib with a text editor and find my button. This is part of the code.

<array class="NSMutableArray" key="NSSubviews"> <object class="NSButton" id="155381693"> <reference key="NSNextResponder" ref="1005"/> <int key="NSvFlags">268</int> <string key="NSFrame">{{20, 303}, {106, 23}}</string> <reference key="NSSuperview" ref="1005"/> <reference key="NSWindow"/> <string key="NSReuseIdentifierKey">_NS:2466</string> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="976550657"> <int key="NSCellFlags">-2080244224</int> <int key="NSCellFlags2">134217728</int> <string key="NSContents">Gradient Button</string> <object class="NSFont" key="NSSupport"> <string key="NSName">LucidaGrande</string> <double key="NSSize">13</double> <int key="NSfFlags">1044</int> </object> <string key="NSCellIdentifier">_NS:2466</string> <reference key="NSControlView" ref="155381693"/> <int key="NSButtonFlags">-2033434369</int> <int key="NSButtonFlags2">162</int> <string key="NSAlternateContents"/> <string key="NSKeyEquivalent"/> <int key="NSPeriodicDelay">400</int> <int key="NSPeriodicInterval">75</int> </object> </object> </array> 

I will try to play the button using this information.

+4
source share
2 answers

OMG, I was blind. Just set the frame style to NSSmallSquareBezelStyle and enter NSMomentaryPushInButton on the button.

I do not need images. I do not need an individual draw with CoreGraphics (for this I made my own class). I do not need to parse xib. I don't need to unload the runtime structures (I did this to find the nessesuary field values ​​in the output to the gradient button created with xib). I had to try all the frame style values ​​from documentation . But if you read the description for NSSmallSquareBezelStyle in the documentation, you understand my confusion: it is very far from the "Gradient" value in IB Wizard.

enter image description here

The correct code is:

 NSButton *gradientButton = [[NSButton alloc] initWithFrame:NSMakeRect(40, 40, 80, 32)]; [gradientButton setButtonType:NSMomentaryPushInButton]; [gradientButton setBezelStyle:NSSmallSquareBezelStyle]; [gradientButton setTitle:@"Title"]; [self.window.contentView addSubview:gradientButton]; 

Result:

enter image description here

+8
source

I believe that the button you are referring to is a custom button and possibly a custom background image, although it can certainly be programmatically created. The problem with these types of buttons is that there were several variations of this button that look very similar but have slight differences.

The easiest way to create these buttons is to use the gradient buttons and drag the + and - icons from the Xcodes stock icons onto them. Otherwise, you can look around a custom NSButton that looks the way you want. I believe that there are some open source programs that they have, but I can’t recall them directly from my head.

0
source

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


All Articles