Set the Italic to the UITextView iOS swift
Solution:
@IBAction func didTapOnItalic(_ sender: Any) {
let textV = self.TextView
if textV != nil {
var fonts = textV.font
fonts = (fonts?.isItalic)! ? fonts?.removeitalic() : fonts?.setItalic()
textV.fontName = fonts!.fontName
}
}
extension UIFont
{
var isItalic: Bool
{
return fontDescriptor.symbolicTraits.contains(.traitItalic)
}
func setItalic()-> UIFont
{
if isItalic {
return self
} else {
var symTraits = fontDescriptor.symbolicTraits
symTraits.insert([.traitItalic])
let fontDescriptorVar = fontDescriptor.withSymbolicTraits(symTraits)
return UIFont(descriptor: fontDescriptorVar!, size: 0)
} }
func removeitalic()-> UIFont
{
if !isItalic {
return self
} else {
var symTraits = fontDescriptor.symbolicTraits
symTraits.remove([.traitItalic])
let fontDescriptorVar = fontDescriptor.withSymbolicTraits(symTraits)
return UIFont(descriptor: fontDescriptorVar!, size: 0)
}
}
}
Comments
Post a Comment