- (CGFloat)calculateHeightOfString:(NSString*)string
{
CGRect firTextRect = [string boundingRectWithSize:CGSizeMake(ScreenWidth-20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil];
return firTextRect.size.height;
}
- (NSMutableAttributedString *)getTextOfLabelWithFirUserName:(NSString *)firUserName secUserName:(NSString*)secUserName content:(NSString*)content
{
NSString *string = nil;
if (firUserName.length > 0) {
if (secUserName.length > 0) {
string = [NSString stringWithFormat:@"%@回复%@:%@",firUserName,secUserName,content];
}
else
{
secUserName = @"";
string = [NSString stringWithFormat:@"%@:%@",firUserName,content];
}
}
else
{
firUserName = @"";
string = [NSString stringWithFormat:@"回复%@:%@",secUserName,content];
}
NSMutableAttributedString *temString = [[NSMutableAttributedString alloc]initWithString:string];
[temString addAttribute:NSForegroundColorAttributeName
value:[UIColor colorWithHexString:@"0084ad"]
range:NSMakeRange(0, firUserName.length)];
[temString addAttribute:NSForegroundColorAttributeName
value:[UIColor colorWithHexString:@"0084ad"]
range:NSMakeRange(firUserName.length + 2, secUserName.length)];
return temString;
}
网友评论