iOS控件--UILabel
2016-03-28 00:00
435 查看
摘要: label的属性和用法
UILabel继承与UIView,是iOS设计非常常用的一个控件
对齐方式textAlignment:
NSTextAlignmentLeft = 0, // Visually left aligned 左对齐
NSTextAlignmentCenter = 1, // Visually centered 居中
NSTextAlignmentRight = 2, // Visually right aligned 右对齐
NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned.
NSTextAlignmentNatural = 4, // Indicates the default alignment for script
文字超长处理lineBreakMode:
NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default 包在用词边界(默认)应该是能够识别空格
NSLineBreakByCharWrapping, // Wrap at character boundaries 包在字符边界
NSLineBreakByClipping, // Simply clip 直接截取
NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz" 头部缩略
NSLineBreakByTruncatingTail, // Truncate at tail of line: "abcd..." 尾部缩略
NSLineBreakByTruncatingMiddle // Truncate middle of line: "ab...yz" 中间缩略
文本基线控制baselineAdjustment:
UIBaselineAdjustmentAlignBaselines = 0, // default. 默认文本最上端与label中间线
UIBaselineAdjustmentAlignCenters, //text中间与label中间线对齐
UIBaselineAdjustmentNone, //text最底端与label中间线对齐
UILabel继承与UIView,是iOS设计非常常用的一个控件
//label初始化 UILabel *lable = [[UILabel alloc] init]; //label的位置 lable.frame = CGRectMake(20, 100, 300, 50); //label的内容 lable.text = @"这是一个比较长的label,这是一个比较长的label,这是一个比较长的label,这是一个比较长的label,这是最后几个结尾字"; //label的背景颜色 lable.backgroundColor = [UIColor yellowColor]; //label内容的颜色 lable.textColor = [UIColor redColor]; //label字体的大小 lable.font = [UIFont systemFontOfSize:30]; //设置阴影颜色 lable.shadowColor = [UIColor blackColor]; //label阴影的偏移量 lable.shadowOffset = CGSizeMake(3, 3); //label的对齐方式 lable.textAlignment = NSTextAlignmentCenter; //label的边缘属性 lable.layer.masksToBounds = YES; //label的圆角 lable.layer.cornerRadius = 20; //label边线颜色 lable.layer.borderColor = [[UIColor purpleColor] CGColor]; //label边线宽度 lable.layer.borderWidth = 3; //文字超长处理 label.lineBreakMode = NSLineBreakByTruncatingMiddle; [self.view addSubview:lable]; UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(20, 250, 200, 50)]; label2.backgroundColor = [UIColor yellowColor]; [self.view addSubview:label2]; //================== //多属性字符串的使用:$700 ,$是红色的,700是黑色的 NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]init]; //NSFontAttributeName字典的key,代表字体 //NSForegroundColorAttributeName 文字颜色 //NSBackgroundColorAttributeName 文字背景色 NSAttributedString *str1 =[[NSAttributedString alloc]initWithString:@"$" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:35],NSForegroundColorAttributeName:[UIColor redColor]}]; NSAttributedString *str2 = [[NSAttributedString alloc]initWithString:@"700" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:40],NSForegroundColorAttributeName:[UIColor blackColor]}]; [attrString appendAttributedString:str1]; [attrString appendAttributedString:str2]; label2.attributedText = attrString; UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(20, 320, 200, 250)]; [self.view addSubview:label3]; label3.backgroundColor = [UIColor yellowColor]; //用户可交互 label3.userInteractionEnabled = YES; //label高亮 label3.highlighted = YES; 7ff8 //label高亮颜色 label3.highlightedTextColor = [UIColor purpleColor]; //label字体大小适应label宽度(与numberOfLines冲突) label3.adjustsFontSizeToFitWidth = YES; label3.text = @"这是一个比较长的label,这是一个比较长的label,这是一个比较长的label,这是一个比较长的label,这是最后几个结尾字"; //多行控制为0时,表示多行 label3.numberOfLines = 0;
对齐方式textAlignment:
NSTextAlignmentLeft = 0, // Visually left aligned 左对齐
NSTextAlignmentCenter = 1, // Visually centered 居中
NSTextAlignmentRight = 2, // Visually right aligned 右对齐
NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned.
NSTextAlignmentNatural = 4, // Indicates the default alignment for script
文字超长处理lineBreakMode:
NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default 包在用词边界(默认)应该是能够识别空格
NSLineBreakByCharWrapping, // Wrap at character boundaries 包在字符边界
NSLineBreakByClipping, // Simply clip 直接截取
NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz" 头部缩略
NSLineBreakByTruncatingTail, // Truncate at tail of line: "abcd..." 尾部缩略
NSLineBreakByTruncatingMiddle // Truncate middle of line: "ab...yz" 中间缩略
文本基线控制baselineAdjustment:
UIBaselineAdjustmentAlignBaselines = 0, // default. 默认文本最上端与label中间线
UIBaselineAdjustmentAlignCenters, //text中间与label中间线对齐
UIBaselineAdjustmentNone, //text最底端与label中间线对齐
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- javascript实现label标签跳出循环操作
- Jquery跨域获得Json时invalid label错误的解决办法
- js 为label标签和div标签赋值的方法
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用中UISearchDisplayController搜索效果的用法
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?