美文网首页
label的行间距

label的行间距

作者: 羊妞麻麻 | 来源:发表于2018-10-08 16:18 被阅读13次

    具体需求效果如下:

    1538986128588.jpg

    具体实现两段文字间的行间距问题。间距是22

    代码块如下

    self.contentLabel.text = log_description;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 22;// 字体的行间距
        
    NSDictionary *attributes = @{
                                     NSFontAttributeName:[UIFont systemFontOfSize:12],
                                     NSParagraphStyleAttributeName:paragraphStyle
                                     };
    self.contentLabel.attributedText = [[NSAttributedString alloc] initWithString: log_description attributes:attributes];
    

    以上就是行间距的具体实现。

    下面说下,这段文案中前端针对服务端返回的数据进行拼接展示问题。其中包括下面几种情况:
    1、当数据大于5条时在最后一个文案描述后面增加等。
    电压100.00V、电流100mA、负载率95.66%、A相温度99℃、B相温度99℃等.

    2、当数据只有1条时。展示效果如下
    电压100.00V。

    3、当数据为2条、3条、4条时。展示效果如下
    电压100.00V、电流100mA。
    电压100.00V、电流100mA、负载率95.66%。
    电压100.00V、电流100mA、负载率95.66%、A相温度99℃。

    具体实现如下:

    NSInteger num = obj.log_list.count > 5 ? 5 : obj.log_list.count;
    NSString *log_description = [NSString string];
    for (NSInteger i = 0; i < num; i++) {
            SCDeviceSeriesModel *seriesModel = [obj.log_list objectAtIndex:i];
            //电压100.00V、电流100mA、负载率95.66%、A相温度99℃、B相温度99℃等.
            NSString * des = [NSString stringWithFormat:@"%@%@%@",seriesModel.series_name,seriesModel.series_value,seriesModel.series_unit];//电压100.00V 电流100mA
            if (i == num - 1) {//是否是最后一条
                if (obj.log_list.count > 5) {//是否数据大于等于5条增加等。
                    des = [des stringByAppendingString:@"等。"];
                }else{
                    des = [des stringByAppendingString:@"。"];
                }
            }else{
                des = [des stringByAppendingString:@"、"];
            }
             log_description = [log_description stringByAppendingString:des];
        }
    

    相关文章

      网友评论

          本文标题:label的行间距

          本文链接:https://www.haomeiwen.com/subject/snrjaftx.html