iOS开发小技巧
遇到的问题: 给Label添加中划线,然后并没有效果
NSString *str = [NSString stringWithFormat:@"合计金额 ¥%.2f",model.amount];
NSDictionary *attrDic = @{
NSStrikethroughStyleAttributeName: @(1),
NSFontAttributeName : Font(FONT_SIZE_12)
};
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str attributes:attrDic];
self.priceLabel.attributedText = attrStr;
解决方案 : 增加一个富文本属性 NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)
NSString *str = [NSString stringWithFormat:@"合计金额 ¥%.2f",model.amount];
NSDictionary *attrDic = @{
NSStrikethroughStyleAttributeName: @(1),
NSFontAttributeName : Font(FONT_SIZE_12),
NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)
};
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str attributes:attrDic];
self.priceLabel.attributedText = attrStr;