在AppDelegate.m文件的didFinishLaunchingWithOptions中对Label的编辑:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
// Override point for customization after application launch.
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10,50,300,30)];//设置大小
label.text =@"标签标签标签标签标签标签标签标签";//设置标签文字
label.textColor = [UIColor blueColor];//设置文字颜色
label.backgroundColor = [UIColor clearColor];//设置标签背景色
label.textAlignment=NSTextAlignmentCenter;//设置文字对齐方式
label.font = [UIFont boldSystemFontOfSize:20];//字号为加粗状态
label.font = [UIFont italicSystemFontOfSize:20];//倾斜,会自动覆盖上一行设置的大小粗度,但是不同的字体效果不同,大家多试试自己查看结果
//便利系统字体库
NSArray *names = [UIFont familyNames];
for (NSString *name in names) {
NSLog(@"%@",name);
}
label.font = [UIFont fontWithName:@"Thonburi"size:25];
label.shadowColor = [UIColor orangeColor];//设置阴影颜色
label.shadowOffset =CGSizeMake(2,2);//设置阴影偏移,宽度是向右偏移,高度是向下偏移,可以为负数
//设置高亮颜色
label.highlighted =NO;//YES高亮,NO不高亮
label.highlightedTextColor = [UIColor redColor];
//根据宽度自动设置文字大小
label.adjustsFontSizeToFitWidth =YES;//根据label的宽度,自动设置font来显示所有的文字
[self.window addSubview:label];//添加到视图
self.window.backgroundColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
returnYES;
}
下面就是最终的运行状态:
不建议一次性讲所有的代码全部复制进去,建议一句句自己敲出来,cmd + R查看结果