Android使用自定义字体的Html字符串与iOS显示的粗体效果不同。
创始人
2024-10-10 14:30:20
0
  1. 在Android中使用Typeface来设置字体,并使用SpannableString对象来设置粗体效果。示例如下:
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);
  1. 在iOS中使用NSAttributedString来设置字体样式,并使用UIFontDescriptor和UIFont中的方法来设置自定义字体的粗体效果。示例如下:
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;

相关内容

热门资讯

透视游戏"拱趴大菠萝... 《透视游戏"拱趴大菠萝怎么开挂"详细辅助AI教程(本然是真的有挂)》 拱趴大菠萝怎么开挂软件透明挂更...
透视教程"hhpok... 此外,数据分析德州(hhpoker是正品吗)辅助神器app还具备辅助透视行为开挂功能,通过对客户hh...
透视攻略"wpk透视... 《透视攻略"wpk透视是真的假的"详细辅助详细教程(切实真的是有挂)》 wpk透视是真的假的软件透明...
透视教学"wepok... 透视教学"wepoker买脚本靠谱吗"详细辅助解密教程(最初真的是有挂);1.wepoker买脚本靠...
透视脚本"来玩app... 透视脚本"来玩app 德州 辅助"详细辅助2025版教程(一向有挂);建议优先通过来玩app 德州 ...
透视有挂"来玩app... 透视有挂"来玩app破解"详细辅助德州教程(起初是真的有挂)准备好在来玩app破解ia的高塔上攀登,...
透视模拟器"wepo... 透视模拟器"wepoker透视辅助下载"详细辅助力荐教程(原生真的是有挂),支持语音通讯、好友开房及...
透视最新"wpk辅助... 透视最新"wpk辅助购买"详细辅助技巧教程(一直真的是有挂);玩家必备必赢加哟《136704302》...
透视苹果版"xpok... 透视苹果版"xpoker辅助怎么用"详细辅助第三方教程(素来是真的有挂)是一款可以让一直输的玩家,快...
透视玄学"hhpok... 透视玄学"hhpoker怎么破解"详细辅助揭秘攻略(一向是有挂)是由北京得hhpoker怎么破解黑科...