У меня есть UITextView, а для строки задан текст с атрибутами, в котором говорится «Подробнее». Я также добавил жест для UITextView. Жест работает, когда щелчок выполняется в любом другом месте, но не при нажатии на «Подробнее».
Мне нужен щелчок, чтобы ответить на щелчок «Подробнее».
Ниже показано, как я реализовал:
//link text
NSDictionary *linkAttributes = @{ NSForegroundColorAttributeName : [UIColor colorWithRed:0.05 green:0.4 blue:0.65 alpha:1.0],
NSFontAttributeName : [UIFont fontWithName:@"Roboto-Regular" size:10.0],
NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle) };
[attributedString setAttributes:linkAttributes range:linkRange];
self.classDesc.userInteractionEnabled = YES;
[self.classDesc addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleExpand:)]];
self.classDesc.selectable = YES;
// Assign attributedText to UILabel
self.classDesc.attributedText = attributedString;
Ниже показан прослушиватель жестов:
- (void)handleExpand:(UITapGestureRecognizer *)tapGesture
{
self.classDesc.text = selectedClasses.classDescription;
[self textViewDidChange:self.classDesc];
CGSize sizeThatFitsTextView = [self.classDesc sizeThatFits:CGSizeMake(self.classDesc.frame.size.width, MAXFLOAT)];
self.descHeight.constant = sizeThatFitsTextView.height ;
}
Любая помощь приветствуется.