I want to render text in italics using core text. In UILabel, I was able to apply italics style(basically slanting the text) for a regular font by adding obliqueness attribute to the NSMutableAttributedString. Please refer the code and output below,
let attributes: [NSAttributedString.Key: Any] =
.font: UIFont(name: "YesevaOne-Regular", size: 20),
.obliqueness: 0.3
]
let label = "FontTest"
let attributedString = NSMutableAttributedString(string: label)
attributedString.addAttributes(attributes, range: NSRange.init(location: 0, length: (label as NSString).length))
fontestLabel.attributedText = attributedString
But, when i do the same in core text, the obliqueness attribute not getting applied to the text, whereas the other attributes like strokewidth, strokecolor was getting applied. I have added the code which i used and output below,
let attrString = NSMutableAttributedString(string: "Font Test")
let attributes: [NSAttributedString.Key: Any] = [
.backgroundColor : UIColor.white.cgColor,
.font : UIFont(name: "YesevaOne-Regular", size: 20)!,
.strokeWidth: -5,
.obliqueness: 0.3,
]
attrString.addAttributes(attributes, range: NSRange(location: 0, length: attrString.length))
let framesetter = CTFramesetterCreateWithAttributedString(attrString as CFAttributedString)
let frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, attrString.length), path, nil)
CTFrameDraw(frame, context)
Please help me, if anyone come across this situation?
PS: The custom font, which i used doesn't have italics ttf.