category用法

来源:互联网 发布:淘宝旗舰店申请 编辑:程序博客网 时间:2024/06/06 03:38
////  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
原创粉丝点击