1

OHAttributeLabel を使用して、ラベルのテキストにカスタム リンクを追加しています。私が使用しているコードを以下に貼り付けます。古いバージョンの OHAttributed ラベル (2010) で動作していましたが、新しいバージョン (最近更新された) では、ラベルのテキストがリンクとしてクリックできなくなりました。

ここで私が見逃していることを誰かアドバイスできますか?

// Set Question Label
Question *question = self._answerForCell.question;
NSString *questionText = [NSString stringWithFormat:@"Q: %@", question.text];
CustomOHAttributLabel *thisQuestionLabel = (CustomOHAttributLabel *)[self.contentView viewWithTag:QUESTIONLABEL_TAG];

//Set up dictionary for question
NSString *questionStr = [question.text stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

NSString *urlForQn = [NSString stringWithFormat:@"dailythingsfm://redirect_to/questions/%@/answers?text=%@&nickname=%@&question_id=%@&question_curious=%i&showEveryOneTab=%i", question.slug, questionStr, [[UserInfo sharedUserInfo] getNickname], question.qid, question.curious, 1];
NSString *qnStartIndex = @"0";
NSString *qnLength = [NSString stringWithFormat:@"%i", [questionText length]];

NSDictionary *qnDict = [NSDictionary dictionaryWithObjectsAndKeys:qnStartIndex, @"start", qnLength, @"length", urlForQn, @"url", nil];
NSArray *array = [NSArray arrayWithObject:qnDict];
[thisQuestionLabel setLabelwithText:questionText fontSize:QUESTION_FONT_SIZE andSubStringToURLArrayViaRange:array withHexColor:@"#555555"];


//Method to set the text in UILabel to a custom link
- (void)setLabelwithText:(NSString *)text fontSize:(CGFloat)fontSize andSubStringToURLArrayViaRange:(NSArray *)array withHexColor:(NSString *)textColor
{
    NSMutableAttributedString *attrStr = [NSMutableAttributedString attributedStringWithString:text];
    [attrStr setFont:[UIFont systemFontOfSize:fontSize]];
    [attrStr setTextColor:[UIColor grayColor]];
    [self removeAllCustomLinks];

    for (NSDictionary *dict in array) {
        NSString *start = [dict objectForKey:@"start"];
        NSString *length = [dict objectForKey:@"length"];
        NSString *url = [dict objectForKey:@"url"];

        NSUInteger startIndex = [start intValue];
        NSUInteger len = [length intValue];

        NSRange range = NSMakeRange(startIndex, len);

        [attrStr setFont:[UIFont boldSystemFontOfSize:fontSize] range:range];
        [attrStr setTextColor:[UIColor colorWithHexString:textColor] range:range];
        [self addCustomLink:[NSURL URLWithString:url] inRange:range];
    }

    self.attributedText = attrStr;
}
4

1 に答える 1

0

最新の OHAttribute ライブラリ (3.2.1) では、addCustomLink の代わりに「setLink」メソッドを使用する必要があります。

于 2012-12-12T06:42:14.487 に答える