0

我正在使用以下代码生成一个按钮,但无法成功更改按钮的前景色。

let button = UIButton(
    type: .close,
    primaryAction: UIAction(
        image: UIImage(systemName: "x.circle"),
        handler: { _ in }
    )
)

我试过了

  • UIImage(systemName: "x.circle")?.withTintColor(.red)

  • UIImage(systemName: "x.circle")?.withTintColor(.systemRed, renderingMode: .alwaysOriginal)

  • button.setTitleColor(.systemRed, for: .normal)

  • 添加配置:

    var config = UIButton.Configuration.borderless()
    config.baseForegroundColor = .systemRed
    button.configuration = config
    
  • 使用不同的符号变体,例如:UIImage(systemName: "x.circle.fill")

在这种特定情况下,我只想更改图像的圆形背景区域的颜色,而不是 X(十字)或按钮的背景。本质上,我想要一个带有灰色 X(十字)的红色实心圆圈。

所以我可以得到这个: 在此处输入图像描述

但我想要更像这样的东西(红色限制在圆圈内): 在此处输入图像描述

4

1 回答 1

0
  1. 将类型从 更改.close.custom

  2. 更改UIImage(systemName: "x.circle")

    UIImage(systemName: "x.circle")?.withTintColor(.systemRed, renderingMode: .alwaysOriginal)

于 2022-01-20T01:29:53.913 回答