iOS lable添加下划线,斜线

如果设置lable一部分有下滑划线、斜线时一部分没有时,需要注意iOS10.3系统以后,必须设置NSBaselineOffsetAttributeName属性,否则文字上下不对齐

        NSString *str = [NSString stringWithFormat:@"%zd~%zd  %zd~%.f",surveyModel.point_s,surveyModel.point_c, surveyModel.point_s,surveyModel.point_c * 1.1];

        NSRange range = [str rangeOfString:@" "];
        NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString:str];

        //
        [attriStr addAttribute:NSStrikethroughStyleAttributeName
                         value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
                         range:NSMakeRange(0,range.location)];
        // iOS10.3系统以后 ,设置该属性才显示
        [attriStr addAttribute:NSBaselineOffsetAttributeName
                         value:@(NSUnderlineStyleSingle)
                         range:NSMakeRange(0,attriStr.length)];
        //
        [attriStr addAttribute:NSForegroundColorAttributeName
                        value:[UIColor darkGrayColor]
                        range:NSMakeRange(0,range.location)];
        
        [self.integralLabel setAttributedText:attriStr];

如果整个lable都有下换线或斜线时,不需要设置上述属性

// 整个都有下划线
     NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"修改收货地址" attributes:@{NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
        self.modifyAddressL.attributedText = attStr;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容