gpt4 book ai didi

ios - 根据屏幕分辨率动态字体大小、样式

转载 作者:行者123 更新时间:2023-11-29 05:50:05 29 4
gpt4 key购买 nike

我试图根据排版动态给出字体大小、样式以及根据屏幕分辨率动态给出的粗细。

我尝试过:

title_home.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.title1)
subtitle_home.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.title2)
subtitle1_home.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.title2)
subtitle2_home.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.title2)

但是我得到的文本是正常大小的。我需要将标题设置为粗体并具有一定的大小,并且它应该根据屏幕的分辨率进行更改。

最佳答案

您可以根据描述符获得粗体/斜体/等首选字体,如下所示:

    let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .headline)
.addingAttributes([.traits : [UIFontDescriptor.TraitKey.weight: UIFont.Weight.semibold]])

let semiboldFont = UIFont(descriptor: descriptor, size: 0)

print(semiboldFont)
//<UICTFont: 0x7fe03300cc30> font-family: ".SFUIText-Semibold"; font-weight: bold; font-style: normal; font-size: 17.00pt

希望有帮助

关于ios - 根据屏幕分辨率动态字体大小、样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55756635/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com