1

https://github.com/honcheng/RTLabelの RTLabel を使用します。テキスト内のリンクを使用する必要があります。

moreInfoString = [NSString stringWithFormat:@"%@ <a href='%@'>%@</a>", text, httpReferense, title];
RTLabel *descriptionSourceLabel = [[RTLabel alloc] init];
descriptionSourceLabel.backgroundColor = [UIColor clearColor];
descriptionSourceLabel.delegate = self;
[descriptionSourceLabel setText:moreInfoString];

ただし、リンク内のテキストは太字です。リンクの太字をキャンセルするには?

4

2 に答える 2

2

プロパティは、リンクのlinkAttributesカスタム スタイル設定に使用できます。linkAttributes空の辞書に設定すると、リンクのスタイルは設定されません。

// Remove all link styles
descriptionSourceLabel.linkAttributes = @{};

// To change only i.e. link color
descriptionSourceLabel.linkAttributes = @{@"color": @"red"};
于 2014-07-02T11:27:05.373 に答える
1

私のやり方は最善ではないと思いますが、とにかく:

関数で- (void)render私は置き換えました:

else if ([component.tagLabel caseInsensitiveCompare:@"a"] == NSOrderedSame)
        {
            if (self.currentSelectedButtonComponentIndex==index)
            {
                if (self.selectedLinkAttributes)
                {
                    [self applyFontAttributes:self.selectedLinkAttributes toText:attrString atPosition:component.position withLength:[component.text length]];
                }
                else
                {
                        [self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
                    [self applyColor:@"#FF0000" toText:attrString atPosition:component.position withLength:[component.text length]];
                }
            }
            else
            {
                if (self.linkAttributes)
                {
                    [self applyFontAttributes:self.linkAttributes toText:attrString atPosition:component.position withLength:[component.text length]];
                }
                else
                {
                        [self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
                    [self applySingleUnderlineText:attrString atPosition:component.position withLength:[component.text length]];
                }
            }

            NSString *value = [component.attributes objectForKey:@"href"];
            value = [value stringByReplacingOccurrencesOfString:@"'" withString:@""];
            [component.attributes setObject:value forKey:@"href"];

            [links addObject:component];
        }

(linkShouldBe_regularFontプロパティを追加-私のカスタムプロパティ、linkShouldBe_regularFont == YESの場合、フォントは通常になります):

else if ([component.tagLabel caseInsensitiveCompare:@"a"] == NSOrderedSame)
        {
            if (self.currentSelectedButtonComponentIndex==index)
            {
                if (self.selectedLinkAttributes)
                {
                    [self applyFontAttributes:self.selectedLinkAttributes toText:attrString atPosition:component.position withLength:[component.text length]];
                }
                else
                {
                    if (!self.linkShouldBe_regularFont) {
                        [self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
                    }
                    [self applyColor:@"#FF0000" toText:attrString atPosition:component.position withLength:[component.text length]];
                }
            }
            else
            {
                if (self.linkAttributes)
                {
                    [self applyFontAttributes:self.linkAttributes toText:attrString atPosition:component.position withLength:[component.text length]];
                }
                else
                {
                    if (!self.linkShouldBe_regularFont) {
                        [self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
                    }
                    [self applySingleUnderlineText:attrString atPosition:component.position withLength:[component.text length]];
                }
            }

            NSString *value = [component.attributes objectForKey:@"href"];
            value = [value stringByReplacingOccurrencesOfString:@"'" withString:@""];
            [component.attributes setObject:value forKey:@"href"];

            [links addObject:component];
        }
于 2013-10-30T06:49:46.103 に答える