#import <UIKit/UIKit.h>
@interface UILabel (categoryTest)
+ (
UILabel*)labelWithFrame:(
CGRect)frmae
text:(
NSString *)text
font:(
NSInteger)font
backgroundColor:(
UIColor *)color;
@end
#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
#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