更改 UIButton 内的 SF 符号大小 [英] Change a SF Symbol size inside a UIButton
问题描述
我正在声明一个这样的按钮:
I am declaring a Button like this :
let menuButton = UIButton()
在那之后,我尝试更改它的参数并在具有此功能的 LBTATools(一个 pod)的帮助下设置他在视图上的位置:
After that I am trying to change it's parameter and set his position on the view with the help of LBTATools (a pod) with this function:
fileprivate func setMenuButtonUI() {
menuButton.setImage(UIImage(systemName: "line.horizontal.3.decrease.circle.fill"), for: .normal)
view.addSubview(menuButton)
menuButton.anchor(top: view.safeAreaLayoutGuide.topAnchor, leading: view.leadingAnchor, bottom: nil, trailing: nil, padding: .init(top: 20, left: 60, bottom: 0, right: 0), size: .init(width: 40, height: 40))
menuButton.setupShadow(opacity: 1, radius: 5, offset: .zero, color: .darkGray)
menuButton.tintColor = .red
}
一切正常,我得到了正确的颜色、位置和大小.唯一的问题是它的大小,我不能用所有常用的方法改变它,比如 menuButton.imageView?.contentMode = .scaleAspectFit
等.
Everything is working well, I get the right color, position and even size.
Only problem is it's size, I cannot change it with all the usual methods like menuButton.imageView?.contentMode = .scaleAspectFit
etc..
可能是因为它是SF符号而不是普通图像.
Probably it comes from the fact that it is a SF Symbol and not a normal image.
非常感谢某人的帮助.
谢谢
推荐答案
您可以使用 SymbolConfiguration
来完成,就像下面的示例代码一样:
You can do it using SymbolConfiguration
like in the sample code below:
let largeConfig = UIImage.SymbolConfiguration(pointSize: 140, weight: .bold, scale: .large)
let largeBoldDoc = UIImage(systemName: "doc.circle.fill", withConfiguration: largeConfig)
button.setImage(largeBoldDoc, for: .normal)
这篇关于更改 UIButton 内的 SF 符号大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!