SF Symbol imageView 不符合pointSize?
SF Symbol imageView does not conform to pointSize?
我的故事板中有一个空的 UIImageView,并且在我的 ViewController.swift 文件中有出口。在 viewDidLoad 中,我调用以下代码:
let config = UIImage.SymbolConfiguration(pointSize: 50, weight: .light)
self.symbol.image = UIImage(systemName: "calendar")
self.symbol.preferredSymbolConfiguration = config
符号加载正常,甚至正确反映了权重。
但是,符号图像的大小仍然与故事板中 UIImageView 的大小相关联,即使我没有对 UIImageView 设置任何限制。据我所知,在 SymbolConfiguration 中声明的 pointSize 对符号图像的大小没有影响。
据我所知,似乎有两种方法可以使 SF Symbols 中的 pointSize 起作用:1. 以编程方式完成所有操作,或者 2. 在 Storyboard / Inspector 中完成所有操作。
有谁知道我做错了什么或者SF Symbols不支持故事板+代码配置吗?
我想通了,你必须在设置配置后调用sizeToFit()
。我猜 Apple 将它留给开发人员调用它,这样他们就可以防止不必要地重新计算 UI 大小,从而可能提高效率。
总之,解决方法是:设置配置后在UIImageView上调用sizeToFit()
。
我通过将 UIImageView
对象的 contentMode
属性 更改为 .center
.
解决了这个问题
let imageView = UIImageView()
imageView.contentModel = .center // This is the key step.
imageView.preferredSymbolConfiguration = .init(pointSize: 10)
iconView.image = UIImage(systemName: "name")
试试这个方法:
let config = UIImage.SymbolConfiguration(pointSize: 50, weight: .light)
self.symbol.image = UIImage(systemName: "calendar", withConfiguration: config)
我的故事板中有一个空的 UIImageView,并且在我的 ViewController.swift 文件中有出口。在 viewDidLoad 中,我调用以下代码:
let config = UIImage.SymbolConfiguration(pointSize: 50, weight: .light)
self.symbol.image = UIImage(systemName: "calendar")
self.symbol.preferredSymbolConfiguration = config
符号加载正常,甚至正确反映了权重。
但是,符号图像的大小仍然与故事板中 UIImageView 的大小相关联,即使我没有对 UIImageView 设置任何限制。据我所知,在 SymbolConfiguration 中声明的 pointSize 对符号图像的大小没有影响。
据我所知,似乎有两种方法可以使 SF Symbols 中的 pointSize 起作用:1. 以编程方式完成所有操作,或者 2. 在 Storyboard / Inspector 中完成所有操作。
有谁知道我做错了什么或者SF Symbols不支持故事板+代码配置吗?
我想通了,你必须在设置配置后调用sizeToFit()
。我猜 Apple 将它留给开发人员调用它,这样他们就可以防止不必要地重新计算 UI 大小,从而可能提高效率。
总之,解决方法是:设置配置后在UIImageView上调用sizeToFit()
。
我通过将 UIImageView
对象的 contentMode
属性 更改为 .center
.
let imageView = UIImageView()
imageView.contentModel = .center // This is the key step.
imageView.preferredSymbolConfiguration = .init(pointSize: 10)
iconView.image = UIImage(systemName: "name")
试试这个方法:
let config = UIImage.SymbolConfiguration(pointSize: 50, weight: .light)
self.symbol.image = UIImage(systemName: "calendar", withConfiguration: config)