gpt4 book ai didi

uibutton - 如何更改 UIButton 中 SF 图标的大小

转载 作者:行者123 更新时间:2023-12-03 15:53:28 40 4
gpt4 key购买 nike

这里很简单的问题。我想更改 UIButton 中 SF 图标的大小。我试过用 20 种方法到星期三。

  • 我尝试设置 EdgeInsets - 没有骰子
  • 我尝试重置
    按钮 ImageView 的 contentMode - 不让步
  • 试图改变图像的字体大小 - 哇?

  • 必须有一个简单的方法来做到这一点。提前致谢。

    最佳答案

    更新:
    看起来您可以使用 Default Symbol Configuration Attributes Inspector 中 UIButton 的设置完成同样的事情。全部归功于下面的 Andrew Kirna。多谢,伙计!

    enter image description here

    成功!!!多亏了一篇关于 SF Symbols 的精彩文章,我终于想出了如何做到这一点。它肯定被埋在那里。

    在 Storyboard 中调整按钮图像的大小真的很好,不是吗?至少我是这么认为的。

    1) 在 Xcode 中将 IconButton.swift 添加到您的项目中。

    import UIKit

    @IBDesignable
    class IconButton: UIButton {
    @IBInspectable var pointSize:CGFloat = 30.0

    override func layoutSubviews() {
    super.layoutSubviews()
    if #available(iOS 13.0, *) {
    let config = UIImage.SymbolConfiguration(pointSize: pointSize)
    setPreferredSymbolConfiguration(config, forImageIn: .normal)
    } else {
    // Fallback on earlier versions
    }
    }
    }

    2) 在storyboard 中创建一个按钮,以SF 图标作为图像。

    3) 转到身份检查器并将按钮的类设置为 IconButton

    4)转到属性检查器并输入您的磅值。请注意,这是 height of the icon X
    3/4。我想要一个 40 x 40 的图标,所以我的点大小是 30。

    5) 在 Storyboard中看到您的图标更新,并为您没有花 3 个小时弄清楚这一点而高兴地笑了 :D

    这篇很棒的文章的一些功劳: https://www.avanderlee.com/swift/sf-symbols-guide/

    关于uibutton - 如何更改 UIButton 中 SF 图标的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59834062/

    40 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com