Skip to content

Subclass of UIButton which utilize tintColor and UIImage rendering mode

License

Notifications You must be signed in to change notification settings

ackdom/TintingButton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TintingButton

Simple UIButton subclass which uses tintColor to color button elements (Title,Image,Border) based on current state.

Why?

UIButton provides functionality to change Title color per UIButton state. You can also change image per state. But since iOS7 introduced renderingmode option to UIImage and face it ... you most likely want just a different color of image than different image per state.

TintColor property can color buttons image (when used as render template) but unfortunately tintColor does not change with UIButton's state. Thats why I decided to create TintingButton

CocoaPods

Currently not supported (or needed more likely)

Usage

TintingButton could be instantiated with "Title-Image-Border", "Title-Image" or Custom colored mode

###All Colored mode

[]

let btnShare = TintingButton(completelyTintedWith: .whiteColor(), activeTintColor: .greenColor())
btnShare.setImage(imageShare, forState: UIControlState.Normal)
btnShare.setTitle(title, forState: UIControlState.Normal)

###Title Image Colored mode

[]

let btnShare = TintingButton(titleAndImageTintedWith: whiteColor(), activeTintColor: .greenColor())
btnShare.setImage(imageShare, forState: UIControlState.Normal)
btnShare.layer.borderColor = .grayColor().CGColor
btnShare.layer.borderWidth = 1
btnShare.setTitle(title, forState: UIControlState.Normal)

###Custom colored mode

TintingButton has closure syntax api to define which element should be tinted and which not. Thats in case you want to include some complex login.

//Same as AllColored mode
let btnShare = TintingButton(tintColor: .whiteColor(), activeTintColor: .greenColor()) { (control) -> Bool in return true}

//Custom mode with your specific logic
let btnShare = TintingButton(tintColor: .whiteColor(), activeTintColor: .greenColor()) { (control) -> Bool in
    
	switch control {
        case .Title,.Image : return yourComputedValue
        case .Border: return anotherComputedValue
    }
}

About

Subclass of UIButton which utilize tintColor and UIImage rendering mode

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages