how to set different font for a UILabel which has text containing both chinese and english characters separately?
I have a UILabel which has tex开发者_如何转开发t containing both chinese and english characters,
now I want to set a font for chinese and another font for english,
how to do this?
There are couple of things that might be of interesting to you:
OHAttributedLabel
and TTTAttributedLabel
OHAttributedLabel stays it is capable of dealing with mixed fonts, color, size, ...
Generally one label can have only one font. Still if you want to show different font for different languages than you can keep different language string in different labels and arrange them the way you want.
See this to decide size of your labels.
Resize UITableViewCell to UILabel's height dynamically
and this is also helpful.
How do I wrap text in a UITableViewCell without a custom cell
I do not believe this is possible. The font
property set in a UILabel
would apply to the entire string specified in the text
property of that UILabel.
I've not tried using chinese font, but you can use the following code to set different / multiple fonts & other properties on Label using NSMutableAttributedString. Foll is my code:
UIFont *ArialFont = [UIFont fontWithName:@"arial" size:18.0];
NSDictionary *arialdict = [NSDictionary dictionaryWithObject: ArialFont forKey:NSFontAttributeName];
NSMutableAttributedString *AattrString = [[NSMutableAttributedString alloc] initWithString:title attributes: arialdict];
UIFont *VerdanaFont = [UIFont fontWithName:@"verdana" size:12.0];
NSDictionary *veradnadict = [NSDictionary dictionaryWithObject:VerdanaFont forKey:NSFontAttributeName];
NSMutableAttributedString *VattrString = [[NSMutableAttributedString alloc]initWithString: newsDate attributes:veradnadict];
[VattrString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:(NSMakeRange(0, 15))];
[AattrString appendAttributedString:VattrString];
lblText.attributedText = AattrString;
Note that lblText is the UILabel, outlet as file owner. One can keep on appending as many NSMutableAttributedString he wants..
Also Note that I've added verdana & arial font in my project & added a plist for the same.
精彩评论