I have a textview in my application. User can select a preferred English font from a dropdown and then type in the textView.
I have 3 more buttons (bold, italic and underline) for text formatting functionality. If the selected font family supports Italic font, then I enable Italic button. Same goes for other 2 buttons.
italicButton.isEnabled = haveItalicFont(forFamilyName: self.selectedFont.familyName)
func haveItalicFont(forFamilyName: String) -> Bool {
let fontNames: [String] = UIFont.fontNames(forFamilyName: forFamilyName)
if fontNames.isEmpty {
return false
}
let italicFontName: String? = fontNames.first(
where: {
let font: UIFont = UIFont(name: $0, size: 8)!
return font.fontDescriptor.symbolicTraits.contains(.traitItalic)
})
return italicFontName != nil
}
As an example when user select Halvetica font, I enable/disable italic button as following.
italicButton.isEnabled = haveItalicFont(forFamilyName: "Halvetica")
But now user select Japanese keyboard and start typing japanese texts. Since Halvetica is an English font, What is the Japanese equivalent of Helvetica which is used for Japanese texts? How do I know it programatically? Which font family I should pass for calling haveItalicFont() method when typing in Japanese?
I did some googling but couldn't find any useful reference.
