From c4886fd42212b4eb3979cffe155e25061869d8c6 Mon Sep 17 00:00:00 2001 From: John Hsu Date: Mon, 27 May 2013 22:18:19 +0800 Subject: [PATCH] Adds UILabel Helper --- UILabel+JOExtension.h | 17 +++++++++++++++++ UILabel+JOExtension.m | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 UILabel+JOExtension.h create mode 100644 UILabel+JOExtension.m diff --git a/UILabel+JOExtension.h b/UILabel+JOExtension.h new file mode 100644 index 0000000..273db9a --- /dev/null +++ b/UILabel+JOExtension.h @@ -0,0 +1,17 @@ +// +// UILabel+JOExtension.h +// +// Copyright (c) 2012. All rights reserved. +// + +#import + +@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 diff --git a/UILabel+JOExtension.m b/UILabel+JOExtension.m new file mode 100644 index 0000000..a5f712b --- /dev/null +++ b/UILabel+JOExtension.m @@ -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