iOS開発UILabel編:iOS 10.3 Labelが設定した中線が突然失効した


iOS10.3更新後、ショッピングモールアプリのようなUI:原価「¥500」のLabel設定のような中線が突然失効した.
これはアップルシステムのバグかもしれません.
根本的な原因:Labelの文字には「中国語」が含まれている限り、リッチテキスト文字列の中線は失効し、以下の2つの方法で解決できます.

1つ目の方法は、人民元記号「¥」と「¥」で、前の1つを使えばいいです。

NSString *market = [NSString stringWithFormat:@"¥%@",@"500"];
        NSMutableAttributedString *attributeMarket = [[NSMutableAttributedString alloc] initWithString:market];
        [attributeMarket setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0,market.length)];

        _marketLabel.attributedText = attributeMarket;

第2の方法:リッチテキストに「中国語」をサポートさせる


リッチテキスト属性を追加:NSBaselineOffsetAttributeName:@(NSUnderlineStyleSingle)
        NSString *market = [NSString stringWithFormat:@"¥%@",@"500"];
        NSMutableAttributedString *attributeMarket = [[NSMutableAttributedString alloc] initWithString:market];
        [attributeMarket setAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)} range:NSMakeRange(0,market.length)];

        _marketLabel.attributedText = attributeMarket;

これで、現在、需要に応じて一時的に解決する方法を選択することができます.アップルは次のバージョンでこのバグを解決すると信じています.