IOS 的工厂模式

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];

这样很省代码。又方便。

有什么不对的请指出  相互交流下  我也是初学者




转载于:https://my.oschina.net/u/1396493/blog/345408

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值