2

我正在尝试创建一个包装器,以便为其他东西(即自定义链接)TTTAttributedLabel提供 UIAppearance 支持linkAttributes和属性activeLinkAttributes

作为界面

@interface MYLabel : TTTAttributedLabel

@property (strong, readwrite, nonatomic) NSString *richText;

@property (strong, nonatomic) NSDictionary *dataTextAttributes UI_APPEARANCE_SELECTOR; //Default: text color blue
@property (strong, nonatomic) NSDictionary *selectedDataTextAttributes UI_APPEARANCE_SELECTOR; //Default: text color red

@end

作为实施

@implementation MYLabel

// .. some code

- (void)setDataTextAttributes:(NSDictionary *)dataTextAttributes {
    _dataTextAttributes = dataTextAttributes;
    self.linkAttributes = dataTextAttributes;
    [self setNeedsLayout];
}

- (void)setSelectedDataTextAttributes:(NSDictionary *)selectedDataTextAttributes {
    _selectedDataTextAttributes = selectedDataTextAttributes;
    self.activeLinkAttributes = selectedDataTextAttributes;
    [self setNeedsLayout];
}

// .. some code

@end

问题是在我手动添加一些链接后,代理正在调用设置器:

[label addLinkToURL:[NSURL URLWithString:@"action://defaultAction"] withRange:result.range]

除非我重用标签,即:在表格视图单元格上,否则链接不会获得正确的样式。

知道为什么这不起作用吗?

顺便说一句:如果我手动设置属性,它可以工作。

4

0 回答 0