ibireme / YYKit

A collection of iOS components.
MIT License
13.99k stars 3.7k forks source link

YYLabel 字符串是中文时候,设置斜体不生效 #607

Closed Liguoju closed 11 months ago

Liguoju commented 11 months ago

YYLabel 字符串是中文时候,设置斜体不生效,英文和数字斜体是生效的,请问怎么解决。 我的电话是+8613041167877. attributeText.addAttributes([NSAttributedString.Key.obliqueness: 0.9], range: item.text?.rangeOf(of: oldText) ?? NSMakeRange(0,item.text?.count ?? 0 ))

Liguoju commented 11 months ago

let matrix = CGAffineTransformMake(0, 0, CGFloat(tanf(10 * Float(M_PI) / 180)), 1, -1, 0) ///字体描述 let desc: UIFontDescriptor = UIFontDescriptor(name: "Helvetica",matrix: matrix) let boldItalicDescriptor = desc.withSymbolicTraits([.traitBold, .traitItalic]) let font = UIFont(descriptor:boldItalicDescriptor!,size: 16) attributeText.addAttribute(.font, value: font, range: item.text?.rangeOf(of: oldText) ?? NSMakeRange(0,item.text?.count ?? 0 ))

Liguoju commented 11 months ago

自测可以了