Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue On link tap changes the color of all links TTTAttributedLabel #542

Closed
dhanrajp4u opened this issue Jun 25, 2015 · 2 comments
Closed

Comments

@dhanrajp4u
Copy link

I am using TTTAttributedLabel for display user tag on table view cell. I have issue when user tap on link one of cell tag user its automatic changes the all cell link string text color to text color.
In simulator working fine but on device getting this effect
Help me, if I am missing something.

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"tttDemo";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryNone;
    }
    NSString *str= @"@dj hello @Dhanraj @pradeep nice @test @well @team yes @good";
    TTTAttributedLabel *summaryLabel =(TTTAttributedLabel *)[cell viewWithTag:55];
    summaryLabel.font = [UIFont systemFontOfSize:14];
    summaryLabel.textColor = [UIColor blackColor];
    summaryLabel.lineBreakMode = NSLineBreakByWordWrapping;
    summaryLabel.numberOfLines = 0;
    summaryLabel.linkAttributes =[NSDictionary dictionaryWithObjectsAndKeys:

                              [UIColor blueColor],(__bridge NSString *)kCTForegroundColorAttributeName,
    
                              //                                    (__bridge id)[[UIColor yellowColor] CGColor],(NSString *)kTTTBackgroundFillColorAttributeName,
    
                              [NSNumber numberWithBool:NO],
                              (__bridge NSString *)kCTUnderlineStyleAttributeName,
    
                              [UIFont boldSystemFontOfSize:14],(__bridge NSString *) kCTFontAttributeName
                              ,nil];
    

    summaryLabel.userInteractionEnabled = YES;
    summaryLabel.delegate=self;
    summaryLabel.text=str;
    self.isAccessibilityElement = NO;
    //For clickable @tagged UserName
    NSRegularExpression *regexp=UserNameRegularExpression();

    [regexp enumerateMatchesInString:summaryLabel.text options:0 range:NSMakeRange(0, str.length) usingBlock:^(NSTextCheckingResult *result, __unused NSMatchingFlags flags, __unused BOOL *stop) {

    ///NSLog(@"loc= %lu length=%lu",(unsigned long)result.range.location,(unsigned long)result.range.length);
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [str substringWithRange:result.range]]];
    [summaryLabel addLinkToURL:url withRange:result.range];
    

    }
    ];

    summaryLabel.activeLinkAttributes=nil;

    return cell;
    }

img_2300
img_2301

@andriichernenko
Copy link

Getting the same issue when presenting UIAlertControl. At the same time, UIAlertView does not cause this. Is there any solution?

Normal state:
screen shot 2015-07-13 at 17 34 24

With UIAlertControl:
screen shot 2015-07-13 at 17 34 11

@andriichernenko
Copy link

Never mind, setting font in inactiveLinkAttributes fixed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants