In Interface Builder components I have Gradient Button
I would like to create this button programmatically. But I can't find combination of button type, bezel style and gradient type to reproduce it. My local goal is to create plus (add) and minus (remove) buttons like this
May be you can also know how to implement part at right of minus? It looks like disabled gradient button.
Update (2012-02-01, 14:52)
I put gradient button on empty xib, open xib with text editor and find my button. This is a part of 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 reproduce button using this information.
OMG, I was blind. Just set bezel style to NSSmallSquareBezelStyle and button type to NSMomentaryPushInButton.
I don't need images. I don't need custom draw with CoreGraphics (I did my own class for that). I don't need to parse xib. I don't need to dump runtime structures (I did it to find nessesuary values of fields in outlet to gradient button created with xib). I had to try all values of bezel style from documentation. But if you read description for NSSmallSquareBezelStyle in documentation you understand my confusion: it's very far from "Gradient" value in IB wizard.
Correct code:
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:
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