1
학습 스위프트. 나는 UIButton
클래스를 보유하고 있습니다.방향 변경 후 사용자 지정 UIButton 배경
class CustomBtn: UIButton {
var shadowLayer: CAShapeLayer!
var shadowAdded: Bool = false
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
override func layoutSubviews() {
super.layoutSubviews()
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
super.drawRect(rect)
shadowLayer = CAShapeLayer()
shadowLayer.path = UIBezierPath(roundedRect: bounds, cornerRadius: 5).CGPath
shadowLayer.fillColor = UIColor(netHex: Colors.Red1.value).CGColor
shadowLayer.shadowColor = UIColor.darkGrayColor().CGColor
shadowLayer.shadowPath = shadowLayer.path
shadowLayer.shadowOffset = CGSize(width: 2.0, height: 2.0)
shadowLayer.shadowOpacity = 0.8
shadowLayer.shadowRadius = 2
layer.insertSublayer(shadowLayer, atIndex: 0)
}
}
그리고 이것은 내 출력 : 여기있다
그러나 나는 방향을 변경할 때
당신은 버튼 배경을 얻기 위해 어떻게 할 것인지 (붉은 색과 그림자) 어떤 방향으로 너비를 채우시겠습니까?
크기 클래스와 자동 레이아웃을 사용하지 않는 이유는 무엇입니까? 스택보기를 사용하면보다 신속하게 대응할 수 있습니다. – Jeet