Merhabalar bu yazımda İOS programlarken UIButton,UISwitcher vs kullandığımız nesnelerin özelliklerini ve projeye eklediğimiz nesnelerin sınıfları yerine kendi sınıfımızı dahil edebiliriz.
Bunun için geliştirilmiş IBDesignable sınıf türü vardır. Ve özellik olarak yani değişken türüde IBInspectable ‘dır kullanırken başlarına @ işareti koymanız gerekli.
Bu nesleri kullanırken hangi elemente sınıf yazmak istiyorsak aşağıdaki verdiğim örnekteki gibi. Buttona yazdığımız sınıfı ekleyebiliriz.
import UIKit import QuartzCore @IBDesignable class ButtonExtender: UIButton { @IBInspectable var borderColor: UIColor = UIColor.whiteColor() { didSet { layer.borderColor = borderColor.CGColor } } @IBInspectable var borderWidth: CGFloat = 1.0 { didSet { layer.borderWidth = borderWidth } } @IBInspectable var cornurRadius: CGFloat = 1.0 { didSet { layer.cornerRadius = cornurRadius clipsToBounds = true } } override init(frame : CGRect) { super.init(frame : frame) setup() configure() } convenience init() { self.init(frame:CGRectZero) setup() configure() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() configure() } override func awakeFromNib() { super.awakeFromNib() setup() configure() } override func prepareForInterfaceBuilder() { super.prepareForInterfaceBuilder() setup() configure() } func setup() { layer.borderColor = UIColor.whiteColor().CGColor layer.borderWidth = 1.0 layer.cornerRadius = 1.0 } func configure() { layer.borderColor = borderColor.CGColor layer.borderWidth = borderWidth layer.cornerRadius = cornurRadius } override func layoutSubviews() { super.layoutSubviews() } }
Böylelikle İOS buttonlarında Default olarak bulunmayan köşe yuvarlama işlemini yapabilir. İstediğiniz türde buttonlar tasarlayabilirsiniz 😉
Tesekkurler işime yaradı 🙂
Many thanks for sharing.