![](/img/trans.png)
[英]CollectionView produces an error on iPhone SE simulator but not on iPhone 11 simulator
[英]NSAttributedString works on iPhone SE in simulator but not iPhone 7
我設置了一個屬性字符串,該字符串在使用iPhone SE而不是iPhone 7的模擬器中可以正常工作。沒有錯誤,它什么也沒顯示。
我還收到關於Expression implicitly coerced from NSObject? to Any
的屬性Expression implicitly coerced from NSObject? to Any
的警告Expression implicitly coerced from NSObject? to Any
Expression implicitly coerced from NSObject? to Any
這是我的代碼:
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
為了驗證這一點,我在應用程序委托中運行了以下代碼。
for family: String in UIFont.familyNames
{
print("\(family)")
for names: String in UIFont.fontNames(forFamilyName: family)
{
print("== \(names)")
}
}
出現此問題的主要原因是字體,如果這是自定義字體,請檢查字體的實際名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.