gpt4 book ai didi

iphone - TTT 归属标签多色字体帮助

转载 作者:行者123 更新时间:2023-12-03 20:33:23 26 4
gpt4 key购买 nike

-(UITableViewCell*) makeLikeCell
{
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SpotlightLikesTableViewCell" owner: self options: nil];

// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
UITableViewCell *cell = [topLevelObjects objectAtIndex:0];


NSString *likeText = [likesAndComments objectAtIndex: kLikeRow];

TTTAttributedLabel *likeLabel = [[[TTTAttributedLabel alloc] initWithFrame:CGRectZero] autorelease];
likeLabel = (TTTAttributedLabel*) [cell viewWithTag: kCaptionTag];
likeLabel.textColor = [UIColor blueColor];
likeLabel.lineBreakMode = UILineBreakModeWordWrap;
[likeLabel setFont: [UIFont fontWithName: @"Helvetica Neue" size: 10]];

[likeLabel setText: likeText afterInheritingLabelAttributesAndConfiguringWithBlock: ^NSAttributedString *(NSMutableAttributedString *mutableAttributedString) {
NSRange colorRange = [[mutableAttributedString string] rangeOfString: @" like this photo." options: NSCaseInsensitiveSearch];

[mutableAttributedString addAttribute:(NSString *) kCTForegroundColorAttributeName value:(id)[[UIColor grayColor] CGColor] range:colorRange];
return mutableAttributedString; }];

return cell;
}

我将 TTT 属性标签添加到我的项目中。我想要有两种不同的字体颜色来显示“喜欢”。然而我的项目不断崩溃。要格式化的示例字符串为:“andrew, john, amos like this photo.”

有什么建议吗? enter image description here

最佳答案

像这样使用

[likeLabel setText:likeText afterInheritingLabelAttributesAndConfiguringWithBlock: ^(NSMutableAttributedString *mutableAttributedString) {
NSRange colorRange = [likeText rangeOfString: @"like this photo." options: NSCaseInsensitiveSearch];
if (colorRange.location != NSNotFound) {
[mutableAttributedString addAttribute:(NSString *) kCTForegroundColorAttributeName value:(id)[[UIColor grayColor] CGColor] range:colorRange];
}
return mutableAttributedString;
}];

关于iphone - TTT 归属标签多色字体帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6081005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com