label 的 工厂模式
.h 文件
@interface LabelFactory : NSObject
//创建白色大字号UILabel
+ (UILabel *)createWhiteBigLabel:(CGRect) frame;
//创建白色小字号UILabel
+ (UILabel *)createWhiteLittleLabel:(CGRect) frame;
//创建黑色大字号UILabel
+ (UILabel *)createBlackBigLabel:(CGRect) frame;
//创建黑色小字号UILabel
+ (UILabel *)createBlackLittleLabel:(CGRect) frame;
@end
.m 文件去实现
#import "LabelFactory.h"
@implementation LabelFactory
//创建白色大字号UILabel
+ (UILabel *)createWhiteBigLabel:(CGRect) frame
{
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:@"Arial" size:20.0f];
[label setBackgroundColor:[UIColor clearColor]];
return label;
}
//创建白色小字号UILabel
+ (UILabel *)createWhiteLittleLabel:(CGRect) frame
{
。。。。。。。。。。。
return label;
}
//创建黑色大字号UILabel
+ (UILabel *)createBlackBigLabel:(CGRect) frame
{
.......
}
//创建黑色小字号UILabel
+ (UILabel *)createBlackLittleLabel:(CGRect) frame
{
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.textColor = [UIColor colorWithRed:143.0f/255.0f green:143.0f/255.0f blue:143.0f/255.0f alpha:1.0];
label.font = [UIFont fontWithName:@"Arial" size:15.0f];
[label setBackgroundColor:[UIColor clearColor]];
return label;
}
@end
对于其他的 文本框 cell 都可以这样去写
页面实现
UIlabel *name = [LabelFactory createWhiteBigLabel:CGRectMake(15.0f, 10.0f, 150.0f, 25.0f)];
[self.view addSubview:name];
这样很省代码。又方便。
有什么不对的请指出 相互交流下 我也是初学者