먼저 스토리 보드에서 버튼에 제약 조건을 설정했습니다. 그런 다음 코드를 수정하여보기 좋게 만들었습니다. 버튼에 그라디언트 기능을 적용하면 이전보다 커집니다. 그걸 어떻게 고쳐 주겠어?그라디언트 적용시 버튼 스트레치
extension UIView {
func applyGradient(colours: [UIColor]) -> Void {
self.applyGradient(colours, locations: nil)
}
func applyGradient(colours: [UIColor], locations: [NSNumber]?) -> Void {
let gradient: CAGradientLayer = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = colours.map { $0.CGColor }
gradient.locations = locations
self.layer.insertSublayer(gradient, atIndex: 0)
}
}
난 그냥 지금 후에는 다음과 같습니다 것을 Here is the pic...
은 ... 아무것도 It goes way outside frame PLZPLZPLZ 시도 않았다 바인딩 기울기가 도와 :) 내가 통해 UR 도움을 주셔서 감사합니다 .. 하나 개의 버튼에 그것을 적용 지금까지
값 유형 CALAyer의 값에는 멤버 clipsToBounds가 없습니다 ... 수행 할 작업 –
죄송합니다. 오타되었습니다. 답변을 업데이트했습니다. – Luke
실제로 그라디언트가 있지만 거기에 추가 된 그림자는 .MaskstoBounds ...가 사라졌습니다. 나는했다. button.layer.borderWidth = 2.9 button.layer.shadowRadius = 1.0 buttonLayer.shadowOffset = CGSizeMake (0,3) 전체 그림자가 사라 졌는데 아마도 원래 프레임에 맞지 않았기 때문이다. 그 –