Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
Renaming to BDBAttributedButton.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbergeron committed Jan 17, 2014
1 parent baadaa3 commit 6771d62
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// BTButton.h
// BDBAttributedButton.h
//
// Copyright (c) 2014 Bradley David Bergeron
//
Expand All @@ -23,14 +23,14 @@
@import UIKit;


FOUNDATION_EXPORT NSString * const BTButtonCornerRadiusName;
FOUNDATION_EXPORT NSString * const BTButtonFillColorName;
FOUNDATION_EXPORT NSString * const BTButtonBorderColorName;
FOUNDATION_EXPORT NSString * const BTButtonBorderWidthName;
FOUNDATION_EXPORT NSString * const BDBAttributedButtonCornerRadiusName;
FOUNDATION_EXPORT NSString * const BDBAttributedButtonFillColorName;
FOUNDATION_EXPORT NSString * const BDBAttributedButtonBorderColorName;
FOUNDATION_EXPORT NSString * const BDBAttributedButtonBorderWidthName;


#pragma mark -
@interface BTButton : UIButton
@interface BDBAttributedButton : UIButton

- (void)setStyleAttributes:(NSDictionary *)attributes forControlState:(UIControlState)state;
- (NSDictionary *)styleAttributesForControlState:(UIControlState)state;
Expand Down
35 changes: 18 additions & 17 deletions BTButton/BTButton.m → BDBAttributedButton/BDBAttributedButton.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// BTButton.m
// BDBAttributedButton.m
//
// Copyright (c) 2014 Bradley David Bergeron
//
Expand All @@ -20,25 +20,25 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#import "BTButton.h"
#import "BDBAttributedButton.h"


NSString * const BTButtonCornerRadiusName = @"com.bradbergeron.BTButtonCornerRadiusName";
NSString * const BTButtonFillColorName = @"com.bradbergeron.BTButtonFillColorName";
NSString * const BTButtonBorderColorName = @"com.bradbergeron.BTButtonBorderColorName";
NSString * const BTButtonBorderWidthName = @"com.bradbergeron.BTButtonBorderWidthName";
NSString * const BDBAttributedButtonCornerRadiusName = @"com.bradbergeron.BDBAttributedButtonCornerRadiusName";
NSString * const BDBAttributedButtonFillColorName = @"com.bradbergeron.BDBAttributedButtonFillColorName";
NSString * const BDBAttributedButtonBorderColorName = @"com.bradbergeron.BDBAttributedButtonBorderColorName";
NSString * const BDBAttributedButtonBorderWidthName = @"com.bradbergeron.BDBAttributedButtonBorderWidthName";


#pragma mark -
@interface BTButton ()
@interface BDBAttributedButton ()

@property (nonatomic) NSMutableDictionary *styleAttributes;

@end


#pragma mark -
@implementation BTButton
@implementation BDBAttributedButton

#pragma mark View Lifecycle
- (id)initWithFrame:(CGRect)frame
Expand All @@ -58,7 +58,8 @@ - (id)initWithFrame:(CGRect)frame
- (void)layoutSubviews
{
[super layoutSubviews];
[super setBackgroundImage:[self btbutton_backgroundImageForState:self.state] forState:self.state];
[super setBackgroundImage:[self BDBAttributedButton_backgroundImageForState:self.state]
forState:self.state];
}

#pragma mark Attributes
Expand All @@ -74,7 +75,7 @@ - (NSDictionary *)styleAttributesForControlState:(UIControlState)state
}

#pragma mark Background Images
static inline NSString *btbutton_NSStringFromUIColor(UIColor *color)
static inline NSString *BDBAttributedButton_NSStringFromUIColor(UIColor *color)
{
if (!color)
return nil;
Expand All @@ -86,7 +87,7 @@ - (NSDictionary *)styleAttributesForControlState:(UIControlState)state
return [NSString stringWithFormat:@"{%f, %f, %f, %f}", c[0], c[1], c[2], c[3]];
}

- (UIImage *)btbutton_backgroundImageForState:(UIControlState)state
- (UIImage *)BDBAttributedButton_backgroundImageForState:(UIControlState)state
{
static NSCache *_backgroundImages;
static dispatch_once_t onceToken;
Expand All @@ -98,21 +99,21 @@ - (UIImage *)btbutton_backgroundImageForState:(UIControlState)state
if (!attributes)
return nil;

CGFloat radius = [attributes[BTButtonCornerRadiusName] floatValue];
CGFloat radius = [attributes[BDBAttributedButtonCornerRadiusName] floatValue];

UIColor *fillColor = attributes[BTButtonFillColorName];
UIColor *fillColor = attributes[BDBAttributedButtonFillColorName];
if (!fillColor)
fillColor = [UIColor clearColor];

UIColor *borderColor = attributes[BTButtonBorderColorName];
UIColor *borderColor = attributes[BDBAttributedButtonBorderColorName];
if (!borderColor)
borderColor = [UIColor clearColor];

CGFloat borderWidth = [attributes[BTButtonBorderWidthName] floatValue];
CGFloat borderWidth = [attributes[BDBAttributedButtonBorderWidthName] floatValue];

NSString *identifier =
[NSString stringWithFormat:@"BTButtonBackgroundImage_r%0.2f_f%@_b%@_w%0.2f", radius,
btbutton_NSStringFromUIColor(fillColor), btbutton_NSStringFromUIColor(borderColor),
[NSString stringWithFormat:@"BDBAttributedButtonBackgroundImage_r%0.2f_f%@_b%@_w%0.2f", radius,
BDBAttributedButton_NSStringFromUIColor(fillColor), BDBAttributedButton_NSStringFromUIColor(borderColor),
borderWidth];

UIImage *image = [_backgroundImages objectForKey:identifier];
Expand Down
15 changes: 15 additions & 0 deletions BDBAttributedButtonDemo.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Pod::Spec.new do |s|
s.name = 'BDBAttributedButton'
s.version = '1.0.0'
s.license = 'MIT'
s.summary = 'A UIButton subclass with easy button styling!'
s.homepage = 'https://github.com/bdbergeron/BDBAttributedButton'
s.authors = { 'Bradley David Bergeron' => '[email protected]' }
s.source = { :git => 'https://github.com/bdbergeron/BDBAttributedButton.git', :tag => s.version.to_s }
s.requires_arc = true

s.platform = :ios, '7.0'

s.source_files = 'BDBAttributedButton/*.{h,m}'
s.public_header_files = 'BDBAttributedButton/*.h'
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@
E84DFAF0188302BE00CCD4DF /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E84DFAE8188302BE00CCD4DF /* Images.xcassets */; };
E84DFAF2188302BE00CCD4DF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E84DFAEC188302BE00CCD4DF /* InfoPlist.strings */; };
E84DFAF3188302BE00CCD4DF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E84DFAEE188302BE00CCD4DF /* main.m */; };
E84DFAF71883031200CCD4DF /* BTButton.m in Sources */ = {isa = PBXBuildFile; fileRef = E84DFAF61883031200CCD4DF /* BTButton.m */; };
E84DFAFE188303E500CCD4DF /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E84DFAFD188303E500CCD4DF /* MainViewController.m */; };
E8674D7D1888C5F200F839E8 /* BDBAttributedButton.m in Sources */ = {isa = PBXBuildFile; fileRef = E8674D7C1888C5F200F839E8 /* BDBAttributedButton.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
E81A2D1B1883026F00B69199 /* BTButtonDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BTButtonDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
E81A2D1B1883026F00B69199 /* BDBAttributedButtonDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BDBAttributedButtonDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
E81A2D1E1883026F00B69199 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
E81A2D201883026F00B69199 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
E81A2D221883026F00B69199 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
E84DFAE5188302BE00CCD4DF /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
E84DFAE6188302BE00CCD4DF /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
E84DFAE8188302BE00CCD4DF /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
E84DFAEA188302BE00CCD4DF /* BTButtonDemo-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "BTButtonDemo-Info.plist"; sourceTree = "<group>"; };
E84DFAEB188302BE00CCD4DF /* BTButtonDemo-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BTButtonDemo-Prefix.pch"; sourceTree = "<group>"; };
E84DFAEA188302BE00CCD4DF /* BDBAttributedButtonDemo-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "BDBAttributedButtonDemo-Info.plist"; sourceTree = "<group>"; };
E84DFAEB188302BE00CCD4DF /* BDBAttributedButtonDemo-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BDBAttributedButtonDemo-Prefix.pch"; sourceTree = "<group>"; };
E84DFAED188302BE00CCD4DF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
E84DFAEE188302BE00CCD4DF /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
E84DFAF51883031200CCD4DF /* BTButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BTButton.h; sourceTree = "<group>"; };
E84DFAF61883031200CCD4DF /* BTButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BTButton.m; sourceTree = "<group>"; };
E84DFAFC188303E500CCD4DF /* MainViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainViewController.h; sourceTree = "<group>"; };
E84DFAFD188303E500CCD4DF /* MainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainViewController.m; sourceTree = "<group>"; };
E8674D7B1888C5F200F839E8 /* BDBAttributedButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BDBAttributedButton.h; sourceTree = "<group>"; };
E8674D7C1888C5F200F839E8 /* BDBAttributedButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDBAttributedButton.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -53,8 +53,8 @@
E81A2D121883026F00B69199 = {
isa = PBXGroup;
children = (
E84DFAF41883031200CCD4DF /* BTButton */,
E84DFAE4188302BE00CCD4DF /* BTButtonDemo */,
E8674D7A1888C5F200F839E8 /* BDBAttributedButton */,
E84DFAE4188302BE00CCD4DF /* BDBAttributedButtonDemo */,
E81A2D1D1883026F00B69199 /* Frameworks */,
E81A2D1C1883026F00B69199 /* Products */,
);
Expand All @@ -63,7 +63,7 @@
E81A2D1C1883026F00B69199 /* Products */ = {
isa = PBXGroup;
children = (
E81A2D1B1883026F00B69199 /* BTButtonDemo.app */,
E81A2D1B1883026F00B69199 /* BDBAttributedButtonDemo.app */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -78,7 +78,7 @@
name = Frameworks;
sourceTree = "<group>";
};
E84DFAE4188302BE00CCD4DF /* BTButtonDemo */ = {
E84DFAE4188302BE00CCD4DF /* BDBAttributedButtonDemo */ = {
isa = PBXGroup;
children = (
E84DFAE5188302BE00CCD4DF /* AppDelegate.h */,
Expand All @@ -87,7 +87,7 @@
E84DFAFB188303E500CCD4DF /* View Controllers */,
E84DFAE9188302BE00CCD4DF /* Supporting Files */,
);
path = BTButtonDemo;
path = BDBAttributedButtonDemo;
sourceTree = "<group>";
};
E84DFAE7188302BE00CCD4DF /* Resources */ = {
Expand All @@ -101,38 +101,38 @@
E84DFAE9188302BE00CCD4DF /* Supporting Files */ = {
isa = PBXGroup;
children = (
E84DFAEA188302BE00CCD4DF /* BTButtonDemo-Info.plist */,
E84DFAEB188302BE00CCD4DF /* BTButtonDemo-Prefix.pch */,
E84DFAEA188302BE00CCD4DF /* BDBAttributedButtonDemo-Info.plist */,
E84DFAEB188302BE00CCD4DF /* BDBAttributedButtonDemo-Prefix.pch */,
E84DFAEC188302BE00CCD4DF /* InfoPlist.strings */,
E84DFAEE188302BE00CCD4DF /* main.m */,
);
path = "Supporting Files";
sourceTree = "<group>";
};
E84DFAF41883031200CCD4DF /* BTButton */ = {
E84DFAFB188303E500CCD4DF /* View Controllers */ = {
isa = PBXGroup;
children = (
E84DFAF51883031200CCD4DF /* BTButton.h */,
E84DFAF61883031200CCD4DF /* BTButton.m */,
E84DFAFC188303E500CCD4DF /* MainViewController.h */,
E84DFAFD188303E500CCD4DF /* MainViewController.m */,
);
path = BTButton;
path = "View Controllers";
sourceTree = "<group>";
};
E84DFAFB188303E500CCD4DF /* View Controllers */ = {
E8674D7A1888C5F200F839E8 /* BDBAttributedButton */ = {
isa = PBXGroup;
children = (
E84DFAFC188303E500CCD4DF /* MainViewController.h */,
E84DFAFD188303E500CCD4DF /* MainViewController.m */,
E8674D7B1888C5F200F839E8 /* BDBAttributedButton.h */,
E8674D7C1888C5F200F839E8 /* BDBAttributedButton.m */,
);
path = "View Controllers";
path = BDBAttributedButton;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
E81A2D1A1883026F00B69199 /* BTButtonDemo */ = {
E81A2D1A1883026F00B69199 /* BDBAttributedButtonDemo */ = {
isa = PBXNativeTarget;
buildConfigurationList = E81A2D471883026F00B69199 /* Build configuration list for PBXNativeTarget "BTButtonDemo" */;
buildConfigurationList = E81A2D471883026F00B69199 /* Build configuration list for PBXNativeTarget "BDBAttributedButtonDemo" */;
buildPhases = (
E81A2D171883026F00B69199 /* Sources */,
E81A2D181883026F00B69199 /* Frameworks */,
Expand All @@ -142,9 +142,9 @@
);
dependencies = (
);
name = BTButtonDemo;
name = BDBAttributedButtonDemo;
productName = BTButtonDemo;
productReference = E81A2D1B1883026F00B69199 /* BTButtonDemo.app */;
productReference = E81A2D1B1883026F00B69199 /* BDBAttributedButtonDemo.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand All @@ -156,7 +156,7 @@
LastUpgradeCheck = 0500;
ORGANIZATIONNAME = "Bradley David Bergeron";
};
buildConfigurationList = E81A2D161883026F00B69199 /* Build configuration list for PBXProject "BTButtonDemo" */;
buildConfigurationList = E81A2D161883026F00B69199 /* Build configuration list for PBXProject "BDBAttributedButtonDemo" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
Expand All @@ -168,7 +168,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
E81A2D1A1883026F00B69199 /* BTButtonDemo */,
E81A2D1A1883026F00B69199 /* BDBAttributedButtonDemo */,
);
};
/* End PBXProject section */
Expand All @@ -190,8 +190,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E8674D7D1888C5F200F839E8 /* BDBAttributedButton.m in Sources */,
E84DFAF3188302BE00CCD4DF /* main.m in Sources */,
E84DFAF71883031200CCD4DF /* BTButton.m in Sources */,
E84DFAEF188302BE00CCD4DF /* AppDelegate.m in Sources */,
E84DFAFE188303E500CCD4DF /* MainViewController.m in Sources */,
);
Expand Down Expand Up @@ -291,10 +291,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BTButtonDemo/Supporting Files/BTButtonDemo-Prefix.pch";
GCC_PREFIX_HEADER = "BDBAttributedButtonDemo/Supporting Files/BDBAttributedButtonDemo-Prefix.pch";
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
INFOPLIST_FILE = "$(SRCROOT)/BTButtonDemo/Supporting Files/BTButtonDemo-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
INFOPLIST_FILE = "BDBAttributedButtonDemo/Supporting Files/BDBAttributedButtonDemo-Info.plist";
PRODUCT_NAME = BDBAttributedButtonDemo;
WARNING_CFLAGS = (
"-Weverything",
"-Wno-unused-exception-parameter",
Expand All @@ -310,10 +310,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BTButtonDemo/Supporting Files/BTButtonDemo-Prefix.pch";
GCC_PREFIX_HEADER = "BDBAttributedButtonDemo/Supporting Files/BDBAttributedButtonDemo-Prefix.pch";
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
INFOPLIST_FILE = "$(SRCROOT)/BTButtonDemo/Supporting Files/BTButtonDemo-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
INFOPLIST_FILE = "BDBAttributedButtonDemo/Supporting Files/BDBAttributedButtonDemo-Info.plist";
PRODUCT_NAME = BDBAttributedButtonDemo;
WARNING_CFLAGS = (
"-Weverything",
"-Wno-unused-exception-parameter",
Expand All @@ -326,7 +326,7 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
E81A2D161883026F00B69199 /* Build configuration list for PBXProject "BTButtonDemo" */ = {
E81A2D161883026F00B69199 /* Build configuration list for PBXProject "BDBAttributedButtonDemo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E81A2D451883026F00B69199 /* Debug */,
Expand All @@ -335,7 +335,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
E81A2D471883026F00B69199 /* Build configuration list for PBXNativeTarget "BTButtonDemo" */ = {
E81A2D471883026F00B69199 /* Build configuration list for PBXNativeTarget "BDBAttributedButtonDemo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
E81A2D481883026F00B69199 /* Debug */,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions BDBAttributedButtonDemo/Supporting Files/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// main.m
//
// Copyright (c) 2014 Bradley David Bergeron
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@import UIKit;

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Loading

0 comments on commit 6771d62

Please sign in to comment.