Latest1.1.0
Homepagehttps://github.com/reesemclean/RDMBorderedButton
LicenseMIT
Platformsios 7.0, requires ARC
Authors

A subclass of UIButton that adds a border.

RDMBorderedButton Screenshot

Usage

In code: Use initWithFrame to create a button and add to a subview.

Interface Builder: Add a button as usual. Set the class to RDMBorderedButton — there are some bugs with iOS 7.1 that require you to set the buttom type to Custom in Interface Builder. All properties can be adjusted using Attributes Inspector. The example project shows this with the black and yellow buttons.

Corner Radius

By default, RDMBorderedButton will adjusts the corner radius of its border based on its frame. You can turn this off with:

button.adjustsCornerRadiusBasedOnFrame = NO; //Default is YES

You can also change the ratio of the corner radius of this automatic adjustment:

button.cornerRadiusRatioToSmallestSide = 1.0/4.0; //Default is 1.0/6.0

Note that changes to Corner Radius will not be animated. If you would like a corner radius change to be animated you will need to animate the key path using CoreAnimation. See the programatic view controller in the example project to see an example of this.

The corner radius can be adjusted manually (this turns off automatic adjustments):

//This will forward the cornerRadius to the button's layer and turn off automatic adjustments
button.cornerRadius = 6.0;

Border Width

The border width of the button can be adjusted programmatically:

button.borderWidth = 2.0;

Color

The text and border color are adjusted together. For normal state they can be changed using either:

button.tintColor = [UIColor greenColor];

or:

 forState:UIControlStateNormal]; 

Disabled state can be adjusted using:

 forState:UIControlStateDisabled]; //Default is [UIColor grayColor]

The text color when highlighted should be changed using:

[self setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted]; //Default is [UIColor whiteColor]

Latest podspec

{
    "name": "RDMBorderedButton",
    "version": "1.1.0",
    "summary": "A subclass of UIButton that adds a border.",
    "description": "RDMBorderedButton is a subclass of UIButton that makes it easy to add a bordered button to your project.n  n                    * Adds a thin border that is the same color as the text. n                    * The border color respects the dimmed tint color when alerts show. n                    * The corner radius is (optionally) automatically set based on button frame.",
    "homepage": "https://github.com/reesemclean/RDMBorderedButton",
    "screenshots": "https://raw.githubusercontent.com/reesemclean/RDMBorderedButton/master/screenshot.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Reese McLean": "[email protected]"
    },
    "social_media_url": "http://twitter.com/reesemclean",
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/reesemclean/RDMBorderedButton.git",
        "tag": "v1.1.0"
    },
    "source_files": "RDMBorderedButton/RDMBorderedButton.{h,m}",
    "public_header_files": "RDMBorderedButton/RDMBorderedButton.h",
    "requires_arc": true
}

Pin It on Pinterest

Share This