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

Commit

Permalink
Adds UILabel Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
John Hsu authored and John Hsu committed May 27, 2013
1 parent 807d245 commit c4886fd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
17 changes: 17 additions & 0 deletions UILabel+JOExtension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// UILabel+JOExtension.h
//
// Copyright (c) 2012. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UILabel (JOExtension)
// Creates transparent UILabel object with specified properties
// Default is text color is black, font is system default
// You should call sizeToFit manually
+(UILabel *)labelWithText:(NSString *)text;
+(UILabel *)labelWithText:(NSString *)text color:(UIColor *)color;
+(UILabel *)labelWithText:(NSString *)text font:(UIFont *)font;
+(UILabel *)labelWithText:(NSString *)text color:(UIColor *)color font:(UIFont *)font;
@end
40 changes: 40 additions & 0 deletions UILabel+JOExtension.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// UILabel+JOExtension.m
//
// Copyright (c) 2012. All rights reserved.
//

#import "UILabel+JOExtension.h"

@implementation UILabel (JOExtension)
+(UILabel *)labelWithText:(NSString *)text
{
return [self labelWithText:text color:nil font:nil];
}

+(UILabel *)labelWithText:(NSString *)text color:(UIColor *)color
{
return [self labelWithText:text color:color font:nil];

}

+(UILabel *)labelWithText:(NSString *)text font:(UIFont *)font
{
return [self labelWithText:text color:nil font:font];
}

+(UILabel *)labelWithText:(NSString *)text color:(UIColor *)color font:(UIFont *)font
{
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
label.backgroundColor = [UIColor clearColor];
if (font) {
label.font = font;
}
if (color) {
label.textColor = color;
}
label.text = text;
return label;
}

@end

0 comments on commit c4886fd

Please sign in to comment.