zoukankan      html  css  js  c++  java
  • iOS UILabel换行同时修改字体大小颜色

        UIButton *onlyPriceBtn = [UIButton buttonWithType:UIButtonTypeCustom];

        onlyPriceBtn.layer.borderColor = [HuConfigration uiColorFromString:@"#F0493D"].CGColor;;

        onlyPriceBtn.layer.borderWidth = 0.5f;

        onlyPriceBtn.layer.cornerRadius = 4;

        onlyPriceBtn.layer.masksToBounds = YES;

        onlyPriceBtn.frame = CGRectMake(15, CGRectGetMaxY(titleLabel.frame)+15, HHBWIDTH - 30, 60);

        [self.bgView addSubview:onlyPriceBtn];

        

        UILabel *btnTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 60)];

        btnTitleLabel.center = onlyPriceBtn.center;

        btnTitleLabel.textColor = kHuColor(#A5A5A5);

        btnTitleLabel.font = [UIFont customFontSize:12];

        btnTitleLabel.numberOfLines = 0;

        btnTitleLabel.text = @"独享价30.0 购买后仅供自己观看学习";//使用斜杠一定不要忘记写numberOfLines 否则无效

        btnTitleLabel.textAlignment = NSTextAlignmentCenter;

        NSMutableAttributedString *attributer = [[NSMutableAttributedString alloc]initWithString:btnTitleLabel.text];

        

        [attributer addAttribute:NSForegroundColorAttributeName

                           value:kHuColor(#F0493D)

                           range:NSMakeRange(0, 8)];

        [attributer addAttribute:NSFontAttributeName

                           value:[UIFont customFontSize:16]

                           range:NSMakeRange(0, 8)];

     

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];//调整行间距

        [paragraphStyle setLineSpacing:4];

        [attributer addAttribute:NSParagraphStyleAttributeName

                           value:paragraphStyle

                           range:NSMakeRange(0, btnTitleLabel.text.length)];

        [paragraphStyle setAlignment:NSTextAlignmentCenter];//为了美观调整行间距,但是当调整行间距时上面设置的居中不能用看 所以要加这一句 [paragraphStyle setAlignment:NSTextAlignmentCenter] 不然没有居中效果

        btnTitleLabel.attributedText = attributer;

        [self.bgView addSubview:btnTitleLabel];

     

    效果图

     

     

  • 相关阅读:
    MyBatis的动态SQL详解
    Mybatis实现Mapper动态代理方式
    解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.
    springmvc前台向后台传值几种方式从简单到复杂
    Maven 项目无法在Ecplise加进tomcat server
    解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.
    tomcat启动startup.bat一闪而过
    用Eclipse创建一个Maven Web项目
    使用Yeoman搭建 AngularJS 应用 (8) —— 让我们搭建一个网页应用
    使用Yeoman搭建 AngularJS 应用 (7) —— 让我们搭建一个网页应用
  • 原文地址:https://www.cnblogs.com/huanghaipo/p/7064144.html
Copyright © 2011-2022 走看看