Ios 我想把不同的标签文字颜色的字幕标签
我想把选框标签放在UITableView单元格中,但使用costomized like标签文本的颜色不同 我使用的是MarqueeLabel类,我能够在UITableViewCell上显示该Marquee标签,这是完美的工作方式 我还尝试了NSAttributedString,但MarqueeLabel不支持不同颜色的标签文本 如果有人有答案,请告诉我 谢谢 这是我的密码Ios 我想把不同的标签文字颜色的字幕标签,ios,xcode,uitableview,uilabel,marquee,Ios,Xcode,Uitableview,Uilabel,Marquee,我想把选框标签放在UITableView单元格中,但使用costomized like标签文本的颜色不同 我使用的是MarqueeLabel类,我能够在UITableViewCell上显示该Marquee标签,这是完美的工作方式 我还尝试了NSAttributedString,但MarqueeLabel不支持不同颜色的标签文本 如果有人有答案,请告诉我 谢谢 这是我的密码 [cell.contentView addSubview:[self createMarqueeLabelWithIndex
[cell.contentView addSubview:[self createMarqueeLabelWithIndex:indexPath.row]];
[cell.textLabel setTextColor:[UIColor redColor] range:NSMakeRange(4, 3)];
-(MarqueeLabel *)createMarqueeLabelWithIndex:(int)index
{
MarqueeLabel *continuousLabel2 = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10,0,300,30) rate:50.0f andFadeLength:10.0f];
continuousLabel2.marqueeType = MLContinuous;
continuousLabel2.continuousMarqueeSeparator = @"";
continuousLabel2.animationCurve = UIViewAnimationOptionCurveLinear;
continuousLabel2.numberOfLines = 1;
continuousLabel2.opaque = NO;
continuousLabel2.enabled = YES;
continuousLabel2.shadowOffset = CGSizeMake(0.0, -1.0);
continuousLabel2.textAlignment = UITextAlignmentLeft;
continuousLabel2.backgroundColor = [UIColor clearColor];
continuousLabel2.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.000];
NSString *strText = [[arrTicker objectAtIndex:index] objectForKey:@"text"];
NSString *strTime = [[arrTicker objectAtIndex:index] objectForKey:@"time"];
NSString *strUser = [[arrTicker objectAtIndex:index] objectForKey:@"userid"];
NSString *strTemp = [NSString stringWithFormat:@"%@ %@ %@ ",strText,strTime,strUser];
continuousLabel2.text = [NSString stringWithFormat:@"%@",strTemp];
return continuousLabel2;
}
不是最好的答案,而是一个肮脏的黑客 经过快速调查,我刚刚添加了
[self-setTextColor:[super-textColor]]代码>至转发属性子标签
- (void)forwardPropertiesToSubLabel {
// Since we're a UILabel, we actually do implement all of UILabel's properties.
// We don't care about these values, we just want to forward them on to our sublabel.
NSArray *properties = @[@"baselineAdjustment", @"enabled", @"font", @"highlighted", @"highlightedTextColor", @"minimumFontSize", @"shadowColor", @"shadowOffset", @"textAlignment", @"textColor", @"userInteractionEnabled", @"text", @"adjustsFontSizeToFitWidth", @"lineBreakMode", @"numberOfLines", @"backgroundColor"];
for (NSString *property in properties) {
id val = [super valueForKey:property];
[self.subLabel setValue:val forKey:property];
}
[self setText:[super text]];
[self setFont:[super font]];
[self setTextColor:[super textColor]];
}
现在我可以通过脚本编辑器更改标签颜色
NB:如您所见,我使用纯文本。对于属性文本,黑客不起作用。不是最好的答案,而是肮脏的黑客
经过快速调查,我刚刚添加了[self-setTextColor:[super-textColor]]代码>至转发属性子标签
- (void)forwardPropertiesToSubLabel {
// Since we're a UILabel, we actually do implement all of UILabel's properties.
// We don't care about these values, we just want to forward them on to our sublabel.
NSArray *properties = @[@"baselineAdjustment", @"enabled", @"font", @"highlighted", @"highlightedTextColor", @"minimumFontSize", @"shadowColor", @"shadowOffset", @"textAlignment", @"textColor", @"userInteractionEnabled", @"text", @"adjustsFontSizeToFitWidth", @"lineBreakMode", @"numberOfLines", @"backgroundColor"];
for (NSString *property in properties) {
id val = [super valueForKey:property];
[self.subLabel setValue:val forKey:property];
}
[self setText:[super text]];
[self setFont:[super font]];
[self setTextColor:[super textColor]];
}
现在我可以通过脚本编辑器更改标签颜色
NB:如您所见,我使用纯文本。对于属性文本,hack不起作用。在单元格中创建uilabel,然后将您的品牌标签分配给属性字符串,然后将uilabel转换为品牌标签,然后将子视图添加到单元格中
希望这对你有帮助。
谢谢。在您的单元格中创建uilabel,然后将您的品牌标签指定给属性字符串,然后将uilabel转换为品牌标签,然后将子视图添加到您的单元格中
希望这对你有帮助。
谢谢。发布一些代码。编辑用于支持属性字符串颜色的字幕标签源代码。然后发出请求,将此颜色支持返回社区。@Json Coco我已经做了这件事,但仍然无法发布一些代码。编辑用于支持属性字符串颜色的字幕标签源代码。然后向社区请求颜色支持。@Json Coco我已经做了那件事,但仍然不起作用