// // EPRadioButton.swift // Crush // // Created by Leon on 2025/7/25. // import UIKit enum EPRadioButtonStyle { /// 圆圈中带勾,未选中时也带勾 case checkIn /// 空圆圈 + 带勾圆圈 case checkEmpty } class EPRadioButton: CLButton { // MARK: - Initialization override init(frame: CGRect) { super.init(frame: frame) contentMode = .center setContentCompressionResistancePriority(.init(760), for: .horizontal) setContentCompressionResistancePriority(.init(760), for: .vertical) setupStyle(.round) touchAreaInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } // MARK: - Public Methods /// 标准:比较通用的圆或方形 func setupStyle(_ radius: IconButtonRadius) { switch radius { case .round: setImage(nil, for: .normal) setImage(UIImage(named: "checkmark_tick"), for: .selected) case .rectangle: // ⚠️这两张图片没有 setImage(UIImage(named: "gamer_game_m_unselected"), for: .normal) setImage(UIImage(named: "gamer_game_m_selected"), for: .selected) touchAreaInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20) default: break } } /// 高级:特别模式,样式不同,用在不同地方(一般是定制) func setupRadioStyle(_ style: EPRadioButtonStyle) { switch style { case .checkIn: let normalImage = MWIconFont.image(fromIcon: .select, size: CGSize(width: 14.4, height: 14.4), color: .c.ctpd) let selectedImage = MWIconFont.image(fromIcon: .select, size: CGSize(width: 14.4, height: 14.4), color: .c.ctpn) setImage(normalImage, for: .normal) setImage(selectedImage, for: .selected) let normalBg = UIImage.circleImage(withColor: .c.csed, bounds: CGRect(x: 0, y: 0, width: 24, height: 24)) let selectedBg = UIImage.circleImage(withColor: .c.cpn, bounds: CGRect(x: 0, y: 0, width: 24, height: 24)) setBackgroundImage(normalBg, for: .normal) setBackgroundImage(selectedBg, for: .selected) case .checkEmpty: setImage(UIImage(named: "checkmark_tick_light"), for: .normal) setImage(UIImage(named: "checkmark_tick"), for: .selected) } } override var isSelected: Bool { didSet { super.isSelected = isSelected } } }