Invalid underline in iOS10.3

 original address

 

    NSString *price = @"¥12.3 ¥23.4";//[NSString stringWithFormat: @"¥%@ ¥%@  %@",goodsItemPrice,goodsItemOriginPrice,numByUserStr]  ;
    NSMutableAttributedString *currentPriceStr = [[NSMutableAttributedString alloc] initWithString:price];
    [currentPriceStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13],NSForegroundColorAttributeName:[UIColor blackColor]} range:NSMakeRange(0, 5)];
    [currentPriceStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor greenColor]} range:NSMakeRange(6, 5)];
    [currentPriceStr addAttributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle)} range:NSMakeRange(6, 5)];
    self.goodsPrice.attributedText = currentPriceStr;

 The above piece of code originally had a dashed line behind the price, but it became invalid in iOS10.3.

 

After testing found:

1. If there are Chinese characters in the string, the setting will be invalid;

2. The underline setting for the string part is also invalid.

 

repair:

Method 1. If underline is set for a whole paragraph, as long as there is no Chinese character string, replace "¥" with "¥".

Method 2, this is more general, no matter whether there is Chinese or some string settings, add a rich text attribute: NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326327765&siteId=291194637