本文主要是介绍UILabel 的简单实用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
UILabel *label1 = [[UILabel alloc]init];label1.frame = CGRectMake(20, 20, 200, 200);label1.backgroundColor = [UIColor yellowColor];//文本label1.text = @"hello,hello,hello,hello,hello,hello,hello,hello,hello,";//文字颜色label1.textColor = [UIColor blackColor];//文字布局模式label1.textAlignment = NSTextAlignmentLeft;label1.alpha = 0.5f;//设置字体label1.font = [UIFont systemFontOfSize:30];label1.font = [UIFont boldSystemFontOfSize:30];label1.font = [UIFont italicSystemFontOfSize:30];label1.font = [UIFont fontWithName:@"Didot" size:30]; //设置字体和字号//设置阴影label1.shadowColor = [UIColor grayColor];label1.shadowOffset = CGSizeMake(1, 2);//换行 labe要有足够空间label1.lineBreakMode = NSLineBreakByWordWrapping; //换行模式label1.numberOfLines = 10;CGSize size = [label1.text sizeWithFont:label1.font constrainedToSize:CGSizeMake(200, 10000) lineBreakMode:NSLineBreakByWordWrapping];label1.frame = CGRectMake(label1.frame.origin.x, label1.frame.origin.y, label1.frame.size.width, size.height);[self.view addSubview:label1];
文本
label1.text =@"hello,hello,hello,hello,hello,hello,hello,hello,hello,";
文字颜色
label1.textColor = [UIColorblackColor];
文字布局模式
label1.textAlignment =NSTextAlignmentLeft;
label1.alpha =0.5f;
设置字体
label1.font = [UIFontsystemFontOfSize:30];
label1.font = [UIFontboldSystemFontOfSize:30];
label1.font = [UIFont thinSystemFontOfSize:30];
label1.font = [UIFontitalicSystemFontOfSize:30];
设置字体和字号
label1.font = [UIFontfontWithName:@"Didot"size:30];
设置阴影
label1.shadowColor = [UIColorgrayColor];
label1.shadowOffset =CGSizeMake(1,2);
换行 labe要有足够空间
label1.lineBreakMode =NSLineBreakByWordWrapping;//换行模式
label1.numberOfLines =10;
CGSize size = [label1.textsizeWithFont:label1.fontconstrainedToSize:CGSizeMake(200,10000) lineBreakMode:NSLineBreakByWordWrapping];
label1.frame =CGRectMake(label1.frame.origin.x
, label1.frame.origin.y
, label1.frame.size.width
, size.height);
这篇关于UILabel 的简单实用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!