繁体   English   中英

SF Symbol imageView 不符合pointSize?

[英]SF Symbol imageView does not conform to pointSize?

我的 storyboard 中有一个空的 UIImageView,并在我的 ViewController.swift 文件中有插座。 在 viewDidLoad 中,我调用了以下代码:

let config = UIImage.SymbolConfiguration(pointSize: 50, weight: .light)
self.symbol.image = UIImage(systemName: "calendar")
self.symbol.preferredSymbolConfiguration = config

符号加载良好,甚至重量也正确反映。

但是,符号图像的大小仍然与 storyboard 中的 UIImageView 的大小相关,即使我没有对 UIImageView 设置任何限制。 据我所知,在 SymbolConfiguration 中声明的 pointSize 对符号图像的大小没有影响。

据我所知,似乎有两种方法可以让 SF Symbols 中的 pointSize 起作用:1. 以编程方式完成所有操作或 2. 在 Storyboard / Inspector 中完成所有操作。

有谁知道我做错了什么或者 SF Symbols 不支持 Storyboard + 代码配置?

我想通了,你必须在设置配置后调用sizeToFit() 我猜苹果把它留给了开发人员来调用它,这样他们就可以防止不必要地重新计算 UI 大小,从而有可能提高效率。

无论如何,解决方案是:设置配置后在 UIImageView 上调用sizeToFit()

我通过将UIImageView object 的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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM