Visual_Novel_iOS/crush/Crush/Src/Components/UI/Buttons/EPRadioButton.swift

77 lines
2.6 KiB
Swift
Raw Normal View History

2025-10-09 10:29:35 +00:00
//
// 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
}
}
}