Coder Social home page Coder Social logo

getmixxd / mrsubtlebutton Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marcransome/mrsubtlebutton

0.0 1.0 0.0 77 KB

A subtle gradient button, derived from NSView.

Home Page: http://marcransome.github.com/MRSubtleButton/

License: MIT License

mrsubtlebutton's Introduction

##MRSubtleButton A subtle gradient button, derived from NSView. No images involved.

Example buttons with custom colours:

Button preview

##Usage MRSubtleButton can be integrated into an existing project using CocoaPods. Simply add the necessary dependency to your Podfile as follows:

platform :osx, '10.7'
pod 'MRSubtleButton'
...

Run pod install to install.

Next, drag a custom view from the object library in Xcode into your UI, and change its class to MRSubtleButton.

Create an outlet for the button and implement the <MRSubtleButtonDelegate> protocol in your controller with the following method (don't forget to #import <MRSubtleButton.h> in your controller):

- (void)MRSubtleButtonEvent:(NSEvent *)event with:(id)sender;

Finally, set the button's delegate to your controller object: [button setDelegate:self] and give the button a title: [button setTitle:@"Hello World!"].

If you have more than one button with the same delegate you can determine which button was pressed by inspecting its title:

- (void)MRSubtleButtonEvent:(NSEvent *)event with:(id)sender
{
  // assuming sender is of class MRSubtleButton
  if ([[sender title] isEqualToString:@"Hello World!"])
  {
    // your button event implementation
  }
}

##Custom colours and fonts Each button's gradient colour and font attributes (both colour and size) are adjustable. Setting the button's colour is as easy as specifying a start and end colour for the gradient (note that the gradient starts at the bottom of the button):

NSColor *start = [NSColor colorWithCalibratedRed:205.0f/255.0f green:183.0f/255.0f blue:158.0f/255.0f alpha:1.0f];
NSColor *end = [NSColor colorWithCalibratedRed:255.0f/255.0f green:239.0f/255.0f blue:213.0f/255.0f alpha:1.0f];

[[self button] setGradientWithStartColor:start endColor:end];

A subtle gradient works best, with an end colour that is just a few shades lighter than the start colour. To reset a button to the default light grey gradient use: [button resetGradient].

Adjusting a button's font attributes is just as easy:

NSFont *buttonFont = [NSFont fontWithName:@"Helvetica" size:18.0f];
NSColor *buttonFontColor = [NSColor colorWithCalibratedRed:139.0f/255.0f green:136.0f/255.0f blue:120.0f/255.0f alpha:1.0f]; 
    
[[self button] setFontAttributesWithFont:buttonFont color:buttonFontColor];

[[self button] setTitle:@"Customised button"];

An example using the preceding code:

Customised button

##Caveats Please note that the source code uses ARC (Automatic Reference Counting) and has only been tested against 10.7 and 10.8 deployment targets.

##License MRSubtleButton is provided under the terms of the MIT License.

##Comments or suggestions? Email me at [email protected] with bugs, feature requests or general comments and follow @marcransome for updates.

mrsubtlebutton's People

Contributors

marcransome avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.