gpt4 book ai didi

ios - NSAttributedString 适用于模拟器中的 iPhone SE,但不适用于 iPhone 7

转载 作者:行者123 更新时间:2023-11-29 00:23:30 25 4
gpt4 key购买 nike

我设置了一个属性字符串,它在使用 iPhone SE 但不是 iPhone 7 的模拟器中工作正常。没有错误,它只是不显示任何内容。

我还收到了关于从 NSObject 隐式强制转换的属性 Expression 的警告?到任何

这是我的代码:

let firstName = "Mark"

let welcomeAttributes = [ NSForegroundColorAttributeName: Constants.APP_TEXT_COLOR,
NSFontAttributeName: Constants.APP_CELL_FONT ]

let userNameAttributes = [ NSForegroundColorAttributeName: Constants.APP_THEME_COLOR,
NSFontAttributeName: Constants.APP_CELL_FONT ]

let unformattedUserFirstName = firstName

let userFirstName = NSAttributedString(string: unformattedUserFirstName, attributes: userNameAttributes)

let unformattedWelcome = "Welcome "

let welcome = NSAttributedString(string: unformattedWelcome, attributes: welcomeAttributes)

let welcomeString = NSMutableAttributedString()

welcomeString.append(welcome)

welcomeString.append(userFirstName)

self.welcomeLabel.attributedText = welcomeString

let welcomeLabel: UILabel = {
let label = UILabel()
label.backgroundColor = .white
label.font = Constants.APP_CELL_FONT
label.textColor = Constants.APP_TEXT_COLOR
let welcomeAttributes = [ NSForegroundColorAttributeName: Constants.APP_TEXT_COLOR,
NSFontAttributeName: Constants.APP_CELL_FONT ]
let unformattedWelcome = "Welcome"
let welcome = NSAttributedString(string: unformattedWelcome, attributes: welcomeAttributes)
let welcomeString = NSMutableAttributedString()
welcomeString.append(welcome)
label.attributedText = welcomeString
return label
}()

static let APP_CELL_FONT = UIFont(name: "Muli", size: 12)
static let APP_TEXT_COLOR:UIColor = UIColor(red: 50.0/255.0, green: 50.0/255.0, blue: 50.0/255.0, alpha: 1.0)
static let APP_THEME_COLOR:UIColor = UIColor(red: 231.0/255.0, green: 76.0/255.0, blue: 60.0/255.0, alpha: 1.0)

安装了这些字体:

Muli
== Muli-Light
== Muli-ExtraLight
== Muli

为了验证这一点,我在应用程序委托(delegate)中运行了以下代码。

    for family: String in UIFont.familyNames
{
print("\(family)")
for names: String in UIFont.fontNames(forFamilyName: family)
{
print("== \(names)")
}
}

最佳答案

出现这个问题主要是字体的问题,如果是自定义字体,就要检查字体的实际名称。

关于ios - NSAttributedString 适用于模拟器中的 iPhone SE,但不适用于 iPhone 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43690119/

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