Typeface customTypeface = Typeface.createFromAsset(getAssets(),"custom_font.ttf");
String htmlString = "Some bold text in custom font";
SpannableString spannableString = new SpannableString(Html.fromHtml(htmlString));
spannableString.setSpan(new StyleSpan(customTypeface.getStyle()), 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannableString);
NSString *htmlString = @"Some bold text in custom font";
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithName:@"CustomFont" size:16.0];
UIFontDescriptor *boldFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
UIFont *boldCustomFont = [UIFont fontWithDescriptor:boldFontDescriptor size:0.0];
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:attributedString];
[mutableAttributedString addAttribute:NSFontAttributeName value:boldCustomFont range:NSMakeRange(0, mutableAttributedString.length)];
textView.attributedText = mutableAttributedString;
下一篇:Android时钟显示选项