category用法

xiaoxiao2021-02-28  49

// // 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
转载请注明原文地址: https://www.6miu.com/read-2170152.html

最新回复(0)