はじめに
今回も備忘録として残します。
コード実装
test.swift
import UIKit
@IBDesignable class RoundedCornersButton: UIButton {
// 角丸の半径(0で四角形)
@IBInspectable var cornerRadius: CGFloat = 0.0
// 枠
@IBInspectable var borderColor: UIColor = UIColor.clear
@IBInspectable var borderWidth: CGFloat = 0.0
override func draw(_ rect: CGRect) {
// 角丸
self.layer.cornerRadius = cornerRadius
self.clipsToBounds = (cornerRadius > 0)
// 枠線
self.layer.borderColor = borderColor.cgColor
self.layer.borderWidth = borderWidth
super.draw(rect)
}
}
実装レイアウトに反映する方法
「show the identity inspector」の「custom class」に先ほど作ったClass名を入れる