簡體   English   中英

字符串中的符號在 iOS 大約 13.3 / XCode 11 / Swift 中更改

[英]Symbol in string changed in iOS circa 13.3 / XCode 11 / Swift

我在 UITableViewCell 派生的 class 中使用復選框符號。 顯示了 class 的初始化方法。 When I upgraded from iOS 12.0 to iOS 13.3, the checkbox symbol has changed as the images below show (left = iOS 12.0, right = iOS 13.3). 這個符號不僅改變了它的外觀,它還改變了它的大小。 您可以在下面的代碼中看到我的解決方法。

如果這對問題有任何影響,我在我的 iOS 13.3 應用程序中刪除了場景支持。

有人可以幫助我了解版本之間的變化嗎? 您對如何避免將來在仍然使用符號的同時進行此類更改有什么建議嗎?

iOS 12.0 iOS 13.3


override init(style: UITableViewCell.CellStyle, reuseIdentifier: String!) {

    super.init(style: style, reuseIdentifier: reuseIdentifier)

    checkboxButton = UIButton(type: .custom)

    // TODO: When drop support for pre iOS 13, #available can be removed as well as the 'else'
    var uncheckedSize: CGFloat
    var checkedSize: CGFloat
    if #available(iOS 13, *) {
        uncheckedSize = 32
        checkedSize = 25
    } else {
        uncheckedSize = 20
        checkedSize = 24
    }
    let unchecked = NSMutableAttributedString(string: "☐", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: uncheckedSize)]);
    let checked = NSMutableAttributedString(string: "☑︎", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: checkedSize)]);
    checkboxButton.setAttributedTitle(unchecked, for: .normal)
    checkboxButton.setAttributedTitle(checked, for: .selected)

    checkboxButton.setTitleColor(UIColor.black, for: .normal)
    checkboxButton.frame = CGRect(x: 0, y: 0, width: CGFloat(44), height: CGFloat(44))

    contentView.addSubview(checkboxButton)

    if #available(iOS 11.0, *) {
        let guide = contentView.safeAreaLayoutGuide // since iOS 11.0
        NSLayoutConstraint.useAndActivate([
            checkboxButton.leadingAnchor.constraint(equalTo: guide.leadingAnchor),
            checkboxButton.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
            checkboxButton.widthAnchor.constraint(equalToConstant: CGFloat(44)),
            checkboxButton.heightAnchor.constraint(equalToConstant: CGFloat(44))
            ])
    } else {
        NSLayoutConstraint.useAndActivate([
            checkboxButton.leadingAnchor.constraint(equalTo: self.leadingAnchor),
            checkboxButton.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
            checkboxButton.widthAnchor.constraint(equalToConstant: CGFloat(44)),
            checkboxButton.heightAnchor.constraint(equalToConstant: CGFloat(44))
            ])
    }
}

iOS System Font在 12 和 13 之間更改。

為避免將來出現此類問題:

  • 使用特定字體而不是系統字體
  • 使用 bitmap 圖形(png)
  • 使用自定義視圖並准確地繪制您想要的外觀

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM