1

我对 UIbutton 中 UIImage 的大小有疑问。

我正在尝试使用 SF 符号 (xmark.circle) 制作一个 UIButton,以向我的应用程序添加一个关闭或关闭按钮并使其更大。图标是这样的... 在此处输入图像描述

为了调整 SF 符号的大小,我看到一位开发人员使用 withConfiguration 并使 UIimage 更大,我检查了它在我的项目中是否有效。

lazy var dismissButton: UIButton = {
    let button = UIButton()
    let large = UIImage.SymbolConfiguration(pointSize: 32, weight: .regular, scale: .default)
    let largeImg = UIImage(systemName: "xmark.circle", withConfiguration: large)
    button.isUserInteractionEnabled = true
    button.setImage(largeImg, for: .normal)
    button.tintColor = .lightGray
    return button
}()

但是,我已经有一个 UIimage 结构,因为我没有添加withConfiguration,所以我在代码中创建按钮时尝试添加 withConfiguration。

我的意思是,我有 Images 结构

struct Images {
    static let minus = UIImage(systemName: "minus")
    static let trash = UIImage(systemName: "trash")
    static let pencil = UIImage(systemName: "pencil")
    static let xmarkCircle = UIImage(systemName: "xmark.circle")
    // with more images...
}

我想在创建按钮时调用 Images 结构

lazy var dismissButton: UIButton = {
    let button = UIButton()
    button.isUserInteractionEnabled = true
    button.setImage(Images.xmarkCircle, for: .normal) // -> like in here
    button.tintColor = .lightGray
    return button
}()

但在这种情况下,由于我只是在 setImage 中调用图标 Images.xmarkCircle,因此我无法将 withConfiguration 分配给该图标。可能,我可以通过配置或其他方式将 Images.xmarkCircle 更改为 UIImage,但我不想让 images 结构中的图标之一具有 withConfiguration 值。

那么,当我在lazy vardismissButton中创建一个按钮时是否可以添加withConfiguration,或者是否有另一种方法可以在代码中调整SFsymbol的大小?

4

0 回答 0