是否可以将常规字体更改为可透明文本的粗体



我有一个带有自定义字体Unica One-Regular的标签。由于它没有大胆的字体,因此我会遇到问题以使其大胆。有什么方法可以使其大胆?这是字体链接。

https://fonts.google.com/specimen/unica ineclection.family=unica noce

预先感谢。

对不起,我在iPhone上,但是,请检查Xcode上字体的确切名称,但此代码应回答您的问题:

let attrs:[String:AnyObject] = [NSFontAttributeName: UIFont(name: "Unica One-Bold", size: 12)!]
        let boldString = NSMutableAttributedString(string: "text", attributes:attrs)
let lbl = UILabel()
lbl.attributedText = boldString

如果不可用大胆的字体文件,则有可能增加字体的大胆性吗?。

简短摘要:如果您有字体属性列表,则可以添加阴性中风宽度。例如(在Swift中(:

import AppKit
guard let chosenFont = NSFont(name: "VTypewriter Underwood", size: 24) else {
    print("No such font")
    exit(1)
}
var fontAttributes = [
    NSAttributedString.Key.font:chosenFont,
    NSAttributedString.Key.strokeWidth:NSNumber(value:-3.0)
]
let fakelyBoldedText = NSAttributedString(string:"Hello World", attributes:fontAttributes)

这不是最佳的;这不是真的大胆。但是,由于中风宽度的值较低(在我的实验中,大约3到-5,可能相对于字体宽度(,它看起来确实是大胆的。

最新更新