-(void)addLabel{

    UILabel *label = [[UILabel alloc]init];
label.backgroundColor = [UIColor grayColor];
[self.view addSubview:label]; label.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *leftic =[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier: constant:];
[self.view addConstraint:leftic]; NSLayoutConstraint *rightic =[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier: constant:-];
[self.view addConstraint:rightic]; NSLayoutConstraint *topic =[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier: constant:];
[self.view addConstraint:topic]; NSLayoutConstraint *heightic =[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier: constant:];
[label addConstraint:heightic]; label.numberOfLines = ; // [self changeColor:label];
// [self changeFontLabel:label font:40];
[self changeColorAndFontLabel:label font:]; } //更改字体
- (void)changeFontLabel:(UILabel *)label font:(int)font
{
//label 需要操作的Label
//font 该字符的字号
NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:@"照片中信息真实有效且清晰可见,包括手持证件人的五官、身份证上的所有信息(请看三遍再上传图片噢)"];
NSRange stringRange = NSMakeRange(, ); //该字符串的位置
[noteString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font] range:stringRange];
[label setAttributedText: noteString]; } //两种字体,两种颜色。
- (void)changeColorAndFontLabel:(UILabel *)label font:(int)font
{
//label 需要操作的Label
//font 该字符的字号
NSMutableAttributedString *noteString = [[NSMutableAttributedString alloc] initWithString:@"照片中信息真实有效且清晰可见,包括手持证件人的五官、身份证上的所有信息(请看三遍再上传图片噢)"];
NSRange stringRange = NSMakeRange(, ); //该字符串的位置
[noteString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font] range:stringRange];
[label setAttributedText: noteString]; //将两个写在同一个方法里可以同时实现:一个label两种字体,一个label两种颜色
//但是分开执行两个方法,后面执行的,可能把前面执行的覆盖掉。
NSRange redRange = NSMakeRange([[noteString string] rangeOfString:@"(请看三遍再上传图片噢)"].location, [[noteString string] rangeOfString:@"(请看三遍再上传图片噢)"].length);
//需要设置的位置
[noteString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange]; //设置颜色
[label setAttributedText:noteString]; } //两种颜色
-(void)changeColor:(UILabel *)label{ //下面更改颜色
NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@"照片中信息真实有效且清晰可见,包括手持证件人的五官、身份证上的所有信息(请看三遍再上传图片噢)"];
NSRange redRange = NSMakeRange([[noteStr string] rangeOfString:@"(请看三遍再上传图片噢)"].location, [[noteStr string] rangeOfString:@"(请看三遍再上传图片噢)"].length);
//需要设置的位置
[noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange]; //设置颜色
[label setAttributedText:noteStr]; }

最新文章

  1. (转)深入理解Java的接口和抽象类
  2. MYSQL加锁的测验
  3. 使用NSKeyedArchiver归档
  4. Python_01 在DOS环境运行python程序
  5. 【c】time.h
  6. WebSocket 实战
  7. gdal读写图像分块处理(精华版)
  8. 贴片方式COB COF COG
  9. lorem ipsum text占位符
  10. 【dp】 poj 1157
  11. [Unity]背包效果-使用NGUI实现物品的拖拽效果Drag
  12. Javascript中变量作用域(2)
  13. elasticsearch 踩坑
  14. XSS(四)攻击防御
  15. CSS3之3D轮播图
  16. JavaSE_坚持读源码_String对象_Java1.7
  17. 日志查看技巧之筛选&去重[排查篇]
  18. understand试用笔记一阅读VS2010项目
  19. cxgrid过滤使用心得
  20. Elasticsearch 5.0 安装 Search Guard 5 插件

热门文章

  1. Mac OS X10.8.3-bash基本命令失效后的修复
  2. Android Studio编译OsmAnd出现警告:GeoPointParserUtil.java使用或覆盖了已过时的 API。有关详细信息请使用-Xlint:deprecation重新编译
  3. 一脸懵逼学习Nginx及其安装,Tomcat的安装
  4. JDK 自带压缩解压流
  5. zookeeper 学习 zookeeper下载部署
  6. mysql inner jion多表查询
  7. [转]JAVA实现SFTP实例
  8. 数仓1.4 |业务数仓搭建| 拉链表| Presto
  9. django-admin 仿写stark组件action,filter筛选过滤,search查询
  10. Nginx的配置安装和使用