You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift中能否添加带问号的UIButton?是否为bezel类型?

回答

当然可以将这种带问号的UIButton添加到你的项目中,以下是几种实用实现方式:

实现方式

1. 系统原生快速实现(iOS 15+)

利用UIButton的配置系统,结合系统问号图标就能快速搞定:

let helpButton = UIButton(type: .system)
// 选择合适的配置风格,比如灰色、tinted或bezel
helpButton.configuration = .gray()
// 设置系统问号图标
helpButton.setImage(UIImage(systemName: "questionmark.circle"), for: .normal)
// 不需要文字的话设置空标题
helpButton.setTitle("", for: .normal)
// 按需调整图标大小和内边距
helpButton.imageView?.contentMode = .scaleAspectFit
helpButton.imageEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4)

2. 自定义样式按钮

如果需要更个性化的外观(比如特定圆角、边框色),可以自定义UIButton子类:

class CustomHelpButton: UIButton {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupStyle()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupStyle()
    }
    
    private func setupStyle() {
        setImage(UIImage(systemName: "questionmark.circle"), for: .normal)
        setTitle("", for: .normal)
        // 自定义边框和圆角
        layer.cornerRadius = 8
        layer.borderWidth = 1
        layer.borderColor = UIColor.systemGray.cgColor
        // 调整内边距
        contentEdgeInsets = UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6)
    }
}

关于Bezel术语的说明

你提到的bezel指的是按钮的边框/外框样式,通常是带有轻微凸起或凹陷质感的边框设计。系统UIButton的.bezel()配置就是这种样式,你可以把它和问号图标结合,得到带bezel边框的问号按钮:

let bezelHelpButton = UIButton(type: .system)
bezelHelpButton.configuration = .bezel()
bezelHelpButton.setImage(UIImage(systemName: "questionmark.circle"), for: .normal)
bezelHelpButton.setTitle("", for: .normal)

内容的提问来源于stack exchange,提问作者Dragounow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 13:12:14