嘗試
的Objective - C
__block BOOL found = NO;
NSMutableAttributedString *attrString = ...
[attrString beginEditing];
[attrString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, attrString.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
if (value) {
UIFont *oldFont = (UIFont *)value;
UIFont *newFont = [oldFont fontWithSize:oldFont.pointSize * 2];
[attrString addAttribute:NSFontAttributeName value:newFont range:range];
found = YES;
}
}];
if (!found) {
// No font was found - do something else?
}
[attrString endEditing];
夫特4
var found = false
var attrString = NSMutableAttributedString()
attributedText.enumerateAttribute(NSAttributedStringKey.font, in: NSMakeRange(0, attributedText.length), options: NSAttributedString.EnumerationOptions(rawValue: 0)) { (value, range, stop) in
if let oldFont = value as? UIFont {
let newFont = oldFont.withSize(oldFont.pointSize * 2)
attributedText.addAttribute(NSAttributedStringKey.font, value: newFont, range: range)
found = true
}
}
if !found {
// No font was found - do something else?
}
attributedText.endEditing()
要麼編輯HTML字符串強制字體大小,或枚舉attributedString和添加正確的字體。 – Larme
如何枚舉歸檔字符串以檢查字體? –
實際上html是來自任何隨機地方,所以我們不能強制他們從服務器,要麼我們可以通過添加一些默認的字體(我不知道很多關於HTML,所以要求)更新HTML或我需要更新默認字體,但我無法做到。 –