18

プロジェクトで TTTAttributedLabel を使用しています。リンク属性を変更して、作成したリンクのデフォルトの色と下線を変更することができました。

NSArray *pKeys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,
                      (id)kCTUnderlineStyleAttributeName
                     , nil];

NSArray *pObjects = [[NSArray alloc] initWithObjects:pAlertColor,[NSNumber numberWithInt:
                                                                             kCTUnderlineStyleNone], nil];

NSDictionary *pLinkAttributes = [[NSDictionary alloc] initWithObjects:pObjects
                                                                  forKeys:pKeys];

self.alertMessage.linkAttributes = pLinkAttributes;
self.alertMessage.activeLinkAttributes = pLinkAttributes;

ただし、リンクをタップすると、他のリンクがタップされたときと同じように、一時的に赤くなることに気付きました。この色を変える必要があります。それがどのように行われるかについての手がかりはありますか?

4

6 に答える 6

17

TTTAttributedLabel のドキュメント、特にactiveLinkAttributesを参照してください。

activeLinkAttributes

@property (nonatomic, strong) NSDictionary *activeLinkAttributes ディスカッション

アクティブな状態のときにリンクに適用される NSAttributedString 属性を含むディクショナリ。nil または空の NSDictionary の場合、アクティブなリンクはスタイルされません。デフォルトのアクティブなリンク スタイルは赤で下線付きです。

で宣言

TTTAttributedLabel.h

于 2015-02-09T14:23:16.930 に答える
6

あなたはこのようなことをすべきです

    NSMutableDictionary *mutableActiveLinkAttributes = [NSMutableDictionary dictionary];
    [mutableActiveLinkAttributes setObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCTUnderlineStyleAttributeName];
    [mutableActiveLinkAttributes setObject:[UIColor greenColor] forKey:(NSString *)kCTForegroundColorAttributeName];   
    label.activeLinkAttributes = [NSDictionary dictionaryWithDictionary:mutableActiveLinkAttributes];
于 2015-02-09T14:43:52.443 に答える
1

属性「activeLinkAttributes」を使用できます

NSMutableDictionary* attributes = [NSMutableDictionary dictionaryWithDictionary:self.attributedLabel.activeLinkAttributes];
[attributes setObject:(__bridge id)[UIColor blueColor].CGColor forKey:(NSString*)kCTForegroundColorAttributeName];
self.attributedLabel.activeLinkAttributes = attributes;
于 2015-02-09T14:22:52.090 に答える