extension UIButton{
func setBackgroundColor(_ color: UIColor, for state: UIControl.State) {
UIGraphicsBeginImageContext(CGSize(width: 1.0, height: 1.0))
guard let context = UIGraphicsGetCurrentContext() else { return }
context.setFillColor(color.cgColor)
context.fill(CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0))
let backgroundImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.setBackgroundImage(backgroundImage, for: state)
}
func setRoundCorner(_ radius : CGFloat){
self.layer.masksToBounds = true
self.layer.cornerRadius = radius
}
}
extension UITextField {
func setBottomBorder() {
self.borderStyle = .none
self.layer.backgroundColor = UIColor.white.cgColor
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.gray500.cgColor
self.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
self.layer.shadowOpacity = 0.8
self.layer.shadowRadius = 0.0
}
func setPlaceHolder(_ text : String, _ color : UIColor, _ font : UIFont) {
self.attributedPlaceholder = NSAttributedString(string: "\(text)", attributes: [NSAttributedString.Key.foregroundColor : color,NSAttributedString.Key.font : font])
}
}
extension UIView : Then {}
public protocol Then {}
extension Then where Self : Any {
public func then(_ block: (Self) throws -> Void) rethrows {
try block(self)
}
}