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;