iOS_Subhra
9/28/2018 - 8:01 PM

Custom Button for IB Design.

Custom Button for IB Design.

//
//  SRCustomButton.swift
//
//  Created by Subhr Roy on 22/09/18.
//  Copyright © 2018 Subhr Roy. All rights reserved.
//

import UIKit

enum ButtonCheckStatus {
	case check
	case uncheck
}

let buttonHexColorCode     = "186BC5"

@IBDesignable  open class SRCustomButton: UIButton{
	
	@IBInspectable var cornerRadius: CGFloat = 3.0 {
		didSet {
			layer.cornerRadius = cornerRadius
		}
	}
	
	var buttonCheck : ButtonCheckStatus = .uncheck{
		
		didSet{
			switch buttonCheck {
				case .check :
					self.setImage(nil, for: .normal)
					self.setImage(UIImage(named: "checkbox.png"), for: .normal)
				case .uncheck:
					self.setImage(nil, for: .normal)
					self.setImage(UIImage(named: "uncheckbox.png"), for: .normal)
			}
		}
		
		willSet{
			switch buttonCheck {
				case .check :
					self.setImage(UIImage(named: "checkbox.png"), for: .normal)
				case .uncheck:
					self.setImage(UIImage(named: "uncheckbox.png"), for: .normal)
			}
		}
		
	}

	
	@IBInspectable var borderWidth: CGFloat = 2.0 {
		didSet {
			layer.borderWidth = borderWidth
		}
	}
	
	@IBInspectable var borderColor : CGColor = UIColor.clear.cgColor{
		
		didSet{
			
			layer.borderColor = borderColor
		}
		
	}
	
	@IBInspectable  var viewBackgroundColor : UIColor = UIColor(buttonHexColorCode) {
		
		didSet{
			
			self.backgroundColor = viewBackgroundColor
		}
		
	}
	
	override open func layoutSubviews() {
		super.layoutSubviews()
		clipsToBounds = true
		
	}
	
}