category用法

移动开发 waitig 622℃ 百度已收录 0评论
//
//  UILabel+categoryTest.h
//  test
//

#import <UIKit/UIKit.h>

@interface UILabel (categoryTest)

// category用法
+ (UILabel*)labelWithFrame:(CGRect)frmae
                      text:(NSString *)text
                      font:(NSInteger)font
           backgroundColor:(UIColor *)color;
@end


//
//  UILabel+categoryTest.m
//  test
//

#import "UILabel+categoryTest.h"

@implementation UILabel (categoryTest)

+ (UILabel*)labelWithFrame:(CGRect)frmae
                      text:(NSString *)text
                      font:(NSInteger)font
           backgroundColor:(UIColor *)color{
    UILabel * label = [[UILabel alloc] initWithFrame:frmae];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.backgroundColor = color;
    return label;
}

@end
//
//  ViewController.m
//  test
//

#import "ViewController.h"
#import "UILabel+categoryTest.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UILabel * lable = [UILabel labelWithFrame:CGRectMake(100, 100, 100, 30)
                                         text:@"text"
                                         font:12
                              backgroundColor:[UIColor redColor]];
    [self.view addSubview:lable];
}


@end

本文由【waitig】发表在等英博客
本文固定链接:category用法
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)