GBA-8-19/Delta/Settings/Syncing/gp_btn.swift
2024-06-14 17:15:51 +08:00

43 lines
1.3 KiB
Swift

//
// gp_btn.swift
// Hthik
//
// Created by 16 on 2024/5/31.
// Copyright © 2024 Hthik. All rights reserved.
//
import Foundation
import UIKit
class ButtonModifier {
//
static func setTitle(of button: UIButton, to title: String, for state: UIControl.State = .normal) {
button.setTitle(title, for: state)
}
//
static func setTitleColor(of button: UIButton, to color: UIColor, for state: UIControl.State = .normal) {
button.setTitleColor(color, for: state)
}
//
static func setBackgroundColor(of button: UIButton, to color: UIColor, for state: UIControl.State = .normal) {
button.setBackgroundImage(color.image(), for: state)
}
//
static func addTarget(to button: UIButton, target: Any?, action: Selector, for event: UIControl.Event = .touchUpInside) {
button.addTarget(target, action: action, for: event)
}
}
extension UIColor {
func image(size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
return UIGraphicsImageRenderer(size: size).image { rendererContext in
self.setFill()
rendererContext.fill(CGRect(origin: .zero, size: size))
}
}
}