本文主要是介绍UILable的使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
UILable 显示字符串的视图控件
UILable是UIView的子视图,拥有和view一样的属性,同时也有自己特有的属性
如:显示内容;显示内容大小、对齐方式、显示颜色;多行显示等
-
- UILabel *label01 = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 50.0, 300.0, 30.0)];
- [self.view addSubview:label01];
- label01.backgroundColor = [UIColor yellowColor];
-
- NSString *text = @"I am learning iOS develping";
- label01.text = text;
-
- label01.textColor = [UIColor redColor];
-
- label01.font = [UIFont systemFontOfSize:16.0];
-
- label01.textAlignment = NSTextAlignmentRight;
- UILabel *label02 = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 100.0, 300.0, 100.0)];
- [self.view addSubview:label02];
-
- label02.backgroundColor = [UIColor clearColor];
-
- label02.textColor = [UIColor redColor];
-
-
- label02.font = [UIFont systemFontOfSize:12.0];
-
- label02.font = [UIFont fontWithName:@"Verdana-Bold" size:12.0];
-
- label02.textAlignment = NSTextAlignmentLeft;
-
- NSString *text02 = @"编程语言是一种语言,只是一种语言。随着时光推移,只要你理解了一种语言的原理";
- label02.text = text02;
-
-
-
- text02 = @"编程语言是一种语言,只是一种语言。随着时光推移,只要你理解了一种语言的原理,你会发现各种语言之间的相似之处 。你所选择的语言,你应该觉得“舒服”,并且能够写出有效(而且简洁)的代码。最重要的,让语言去适应项目,反之亦然";
- label02.text = text02;
-
- label02.numberOfLines = 0;
-
- label02.lineBreakMode = NSLineBreakByWordWrapping;
-
- CGSize size = [label02.text boundingRectWithSize:CGSizeMake(label02.bounds.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0]} context:nil].size;
-
- CGRect rect = label02.frame;
- rect.size.height = size.height;
- label02.frame = rect;
-
- label02.shadowColor = [UIColor yellowColor];
- label02.shadowOffset = CGSizeMake(label02.bounds.size.width + 10.0, label02.bounds.size.height + 10.0);
-
- NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text02];
- NSString *setText = @"编程语言是一种语言";
- NSRange range = [text02 rangeOfString:setText];
-
- [attributedText addAttribute:NSForegroundColorAttributeName
- value:[UIColor brownColor]
- range:range];
-
- [attributedText addAttribute:NSFontAttributeName
- value:[UIFont systemFontOfSize:20.0]
- range:range];
- label02.attributedText = attributedText;
这篇关于UILable的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!