patbef-iOS/Befund/Core/Extensions/Button.swift

27 lines
754 B
Swift
Raw Normal View History

2024-01-29 16:20:42 +01:00
//
// Button.swift
// Befund
//
// Created by Irakli Abetschkhrischwili on 02.06.22.
// Copyright © 2022 MVZ Dr. Stein und Kollegen. All rights reserved.
import Foundation
import UIKit
extension UIButton
{
/**
* Sets the background color for UIButton for a state
*/
func setBackgroundColor(color: UIColor, forState: UIControl.State)
{
UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
UIGraphicsGetCurrentContext()!.setFillColor(color.cgColor)
UIGraphicsGetCurrentContext()!.fill(CGRect(x: 0, y: 0, width: 1, height: 1))
let colorImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.setBackgroundImage(colorImage, for: forState)
}
}