9

ラベル内のテキストに下線を引こうとしています。ただし、ラベル内のテキスト全体の範囲を取得する方法がわかりません。これは私がこれまでに持っているものです:

NSMutableAttributedString *mat = [self.tableLabel.attributedText mutableCopy];
[mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range://??];
self.tableLabel.attributedText = mat;

レンジには何を入れればいいですか?

4

2 に答える 2

22

使用したい範囲について:

NSMakeRange (0, mat.length);

このような:

NSMutableAttributedString *mat = [self.tableLabel.attributedText mutableCopy];
[mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:NSMakeRange (0, mat.length)];
self.tableLabel.attributedText = mat;
于 2013-03-10T22:51:59.947 に答える
1
NSMutableAttributedString *attributedString =[[NSMutableAttributedString alloc] initWithString:strComplete];

[attributedString addAttribute:NSUnderlineStyleAttributeName
                         value:@(NSUnderlineStyleSingle)
                         range:[strComplete rangeOfString:strFirst]];

[attributedString addAttribute:NSForegroundColorAttributeName
                         value:[UIColor redColor]
                         range:[strComplete rangeOfString:strSecond]];


cell.textLabel.attributedText = attributedString;
于 2017-09-20T10:16:53.077 に答える