欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

实现每个点赞用户点击的带属性的字符串

发布时间:2023/12/19 39 豆豆
生活随笔 收集整理的这篇文章主要介绍了 实现每个点赞用户点击的带属性的字符串 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2019独角兽企业重金招聘Python工程师标准>>>

#pragma mark - 点击各个点赞用户-(void)setClicked:(TweetCell *)cell andOSCTweet:(OSCTweet *)tweet {NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:tweet.likeListString];//遍历每个点赞用户的名称for (int i = 0; i < 3 && i < tweet.likeCount; i++){OSCUser *user = tweet.likeList[i];NSRange nameRange = [tweet.likeListString rangeOfString:user.name];[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor nameColor] range:nameRange];[cell.likeListLabel addLinkToURL:[NSURL URLWithString:[NSString stringWithFormat:@"userid:%lld", user.userID]] withRange:nameRange];}NSRange numRange = [tweet.likeListString rangeOfString:[NSString stringWithFormat:@"%d人", tweet.likeCount]];[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor nameColor] range:numRange];[cell.likeListLabel addLinkToURL:[NSURL URLWithString:[NSString stringWithFormat:@"tweetid:%lld", tweet.tweetID]] withRange:numRange];cell.likeListLabel.attributedText = attributedString;cell.likeListLabel.delegate = self;} #pragma mark - TTTAttributedLabelDelegate - (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {NSArray *arrayStr = [url.absoluteString componentsSeparatedByString:@":"];if ([arrayStr[0] isEqualToString:@"userid"]) {UserDetailsViewController *userDetailsVC = [[UserDetailsViewController alloc] initWithUserID:((NSNumber *)arrayStr[1]).longLongValue];[self.navigationController pushViewController:userDetailsVC animated:YES];} else {TweetsLikeListViewController *likeListCtl = [[TweetsLikeListViewController alloc] initWithtweetID:((NSNumber *)arrayStr[1]).longLongValue];[self.navigationController pushViewController:likeListCtl animated:YES];}}

转载于:https://my.oschina.net/pingAds/blog/416401

总结

以上是生活随笔为你收集整理的实现每个点赞用户点击的带属性的字符串的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。