[英]How do you make a UIButton with no text be the size of its image?
I created a UIButton
in Interface Builder that consists of only an SF Symbol and no text.我在 Interface Builder 中创建了一个
UIButton
,它只包含一个 SF Symbol 而没有文本。 The button draws with insets around the image, which affects how it's positioned with constraints.该按钮在图像周围绘制插图,这会影响它如何通过约束定位。 How do I remove that extra space, so that the button view is just the size of the SF Symbol image?
如何删除多余的空间,以便按钮视图只是 SF Symbol 图像的大小?
A button will take the size of the image by default.默认情况下,按钮将采用图像的大小。 but since SF-Symbols are vectors, they can be scaled to any size.
但由于 SF-Symbols 是向量,它们可以缩放到任何大小。 Each symbol has a few predefined sizes that you can choose:
每个符号都有一些您可以选择的预定义大小:
Also, you can set your own size in the code:此外,您可以在代码中设置自己的尺寸:
let config = UIImage.SymbolConfiguration(pointSize: 160, weight: .bold, scale: .large)
let largeChevronImage = UIImage(systemName: "chevron.right.circle.fill", withConfiguration: config)
button.setImage(largeChevronImage, for: .normal)
Some images and SF-Symbols have some paddings around their content.一些图像和 SF 符号在其内容周围有一些填充。 You can control the size of the padding by setting the
ContentEdgeInsets
您可以通过设置
ContentEdgeInsets
来控制填充的大小
You can clip the bounds to hide the out of frame content您可以裁剪边界以隐藏帧外内容
All SF-Symbols have same size所有 SF-Symbols 具有相同的大小
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.