Skip to content

Commit

Permalink
clean up and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed May 6, 2014
1 parent 7faa771 commit eb19366
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 38 deletions.
13 changes: 3 additions & 10 deletions BButton/Classes/BButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ @interface BButton ()
- (void)setup;
- (void)setTextAttributesForStyle:(BButtonStyle)aStyle;

- (NSString *)stringFromFontAwesomeIcon:(FAIcon)icon;

+ (UIColor *)colorForButtonType:(BButtonType)type style:(BButtonStyle)style;
+ (UIColor *)colorForV2StyleButtonWithType:(BButtonType)type;
+ (UIColor *)colorForV3StyleButtonWithType:(BButtonType)type;
Expand Down Expand Up @@ -117,7 +115,7 @@ - (instancetype)initWithFrame:(CGRect)frame
if (self) {
[[self titleLabel] setFont:[UIFont fontWithName:kFontAwesomeFont size:fontSize]];
[[self titleLabel] setTextAlignment:NSTextAlignmentCenter];
[self setTitle:[self stringFromFontAwesomeIcon:icon]
[self setTitle:[NSString fa_stringForFontAwesomeIcon:icon]
forState:UIControlStateNormal];
}
return self;
Expand Down Expand Up @@ -205,7 +203,7 @@ - (void)setColor:(UIColor *)newColor
{
_color = newColor;

if([newColor bb_isLightColor]) {
if ([newColor bb_isLightColor]) {
[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self setTitleShadowColor:[[UIColor whiteColor] colorWithAlphaComponent:0.6f] forState:UIControlStateNormal];

Expand Down Expand Up @@ -257,7 +255,7 @@ - (void)setType:(BButtonType)type

- (void)addAwesomeIcon:(FAIcon)icon beforeTitle:(BOOL)before
{
NSString *iconString = [self stringFromFontAwesomeIcon:icon];
NSString *iconString = [NSString fa_stringForFontAwesomeIcon:icon];
self.titleLabel.font = [UIFont fontWithName:kFontAwesomeFont
size:self.titleLabel.font.pointSize];

Expand All @@ -275,11 +273,6 @@ - (void)addAwesomeIcon:(FAIcon)icon beforeTitle:(BOOL)before
[self setTitle:title forState:UIControlStateNormal];
}

- (NSString *)stringFromFontAwesomeIcon:(FAIcon)icon
{
return [NSString fa_stringFromFontAwesomeForIcon:icon];
}

+ (UIColor *)colorForButtonType:(BButtonType)type style:(BButtonStyle)style
{
switch (style) {
Expand Down
15 changes: 4 additions & 11 deletions BButton/Classes/NSString+FontAwesome.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
//
// Created by Pit Garbe on 27.09.12.
// Updated to Font Awesome 3.1.1 on 17.05.2013.
// Copyright (c) 2012 Pit Garbe. All rights reserved.
//
// https://github.com/leberwurstsaft/FontAwesome-for-iOS
//
//
// * The Font Awesome font is licensed under the SIL Open Font License
// http://scripts.sil.org/OFL
//
//
// * Font Awesome CSS, LESS, and SASS files are licensed under the MIT License
// * Font Awesome CSS, LESS, and SASS files are licensed under the MIT License
// http://opensource.org/licenses/mit-license.html
//
//
Expand All @@ -35,12 +28,12 @@
/**
* A string constant for the Font Awesome font family name.
*/
extern NSString * const kFontAwesomeFont;
FOUNDATION_EXPORT NSString * const kFontAwesomeFont;

/**
* A constant describing the available Font Awesome Icons.
*/
typedef NS_ENUM(NSUInteger, FAIcon){
typedef NS_ENUM(unsigned short, FAIcon) {
FAGlass = 0xf000,
FAMusic = 0xf001,
FASearch = 0xf002,
Expand Down Expand Up @@ -454,6 +447,6 @@ typedef NS_ENUM(NSUInteger, FAIcon){

@interface NSString (FontAwesome)

+ (NSString *)fa_stringFromFontAwesomeForIcon:(FAIcon)icon;
+ (NSString *)fa_stringForFontAwesomeIcon:(FAIcon)icon;

@end
14 changes: 4 additions & 10 deletions BButton/Classes/NSString+FontAwesome.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
//
// Created by Pit Garbe on 27.09.12.
// Updated to Font Awesome 3.1.1 on 17.05.2013.
// Copyright (c) 2012 Pit Garbe. All rights reserved.
//
// https://github.com/leberwurstsaft/FontAwesome-for-iOS
//
//
// * The Font Awesome font is licensed under the SIL Open Font License
// http://scripts.sil.org/OFL
//
//
// * Font Awesome CSS, LESS, and SASS files are licensed under the MIT License
// * Font Awesome CSS, LESS, and SASS files are licensed under the MIT License
// http://opensource.org/licenses/mit-license.html
//
//
Expand All @@ -36,8 +29,9 @@

@implementation NSString (FontAwesome)

+ (NSString *)fa_stringFromFontAwesomeForIcon:(FAIcon)icon{
return [NSString stringWithFormat:@"%C", (unsigned short)icon ];
+ (NSString *)fa_stringForFontAwesomeIcon:(FAIcon)icon
{
return [NSString stringWithFormat:@"%C", icon];
}

@end
4 changes: 0 additions & 4 deletions BButtonDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
88F28F58183337F40044C99F /* UIColor+BButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+BButton.m"; sourceTree = "<group>"; };
88F28F5A183337F40044C99F /* FontAwesome.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = FontAwesome.ttf; sourceTree = "<group>"; };
88F28F65183338210044C99F /* BButton.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = BButton.podspec; sourceTree = "<group>"; };
88F28F66183338210044C99F /* FontAwesomeIcons.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = FontAwesomeIcons.html; sourceTree = "<group>"; };
88F28F67183338210044C99F /* LICENSE.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE.txt; sourceTree = "<group>"; };
88F28F68183338210044C99F /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -103,9 +101,7 @@
children = (
88F28F4F183337F40044C99F /* BButton */,
88F28F65183338210044C99F /* BButton.podspec */,
88F28F67183338210044C99F /* LICENSE.txt */,
88F28F68183338210044C99F /* README.md */,
88F28F66183338210044C99F /* FontAwesomeIcons.html */,
88F28F20183336920044C99F /* BButtonDemo */,
88F28F3F183336920044C99F /* BButtonDemoTests */,
88F28F19183336920044C99F /* Frameworks */,
Expand Down
6 changes: 3 additions & 3 deletions BButtonDemoTests/BButtonDemoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ - (void)testButtonClassInitMethods

- (void)testFontAwesome
{
NSString *icon = [NSString fa_stringFromFontAwesomeForIcon:FAWarning];
NSString *icon = [NSString fa_stringForFontAwesomeIcon:FAWarning];
XCTAssertNotNil(icon, @"Icon should not be nil");

NSString *btnTitle = @"Button Title";
Expand All @@ -101,15 +101,15 @@ - (void)testFontAwesome
[btn addAwesomeIcon:i beforeTitle:NO];
XCTAssertEqual([btn.titleLabel.text length], [btnTitle length] + 2, @"Button title length should be 2 characters longer after adding icon");

icon = [NSString fa_stringFromFontAwesomeForIcon:i];
icon = [NSString fa_stringForFontAwesomeIcon:i];
NSString *btnIcon = [btn.titleLabel.text substringFromIndex:[btn.titleLabel.text length] - 1];
XCTAssert([btnIcon isEqualToString:icon], @"Last character in button title should equal FA icon");

i = FATerminal;
[btn addAwesomeIcon:i beforeTitle:YES];
XCTAssertEqual([btn.titleLabel.text length], [btnTitle length] + 4, @"Button title length should be 4 characters longer after adding 2 icons");

icon = [NSString fa_stringFromFontAwesomeForIcon:i];
icon = [NSString fa_stringForFontAwesomeIcon:i];
btnIcon = [btn.titleLabel.text substringToIndex:1];
XCTAssert([btnIcon isEqualToString:icon], @"First character in button title should equal FA icon");
}
Expand Down

0 comments on commit eb19366

Please sign in to comment.