Swift에는 UIButton Type이 있습니다.custom의 하위 클래스 만들기
이 클래스를 단추에 적용하는 방법으로, Storyboard에 대해서는 Xcode의 사용자 정의 Class에서 클래스 이름을 설정하고, Button의 Type을 사용자 정의로 설정하십시오.이것을 잊어버리면 버튼이 의도적인 행동이 되지 않는다.

그래서 하위 클래스에서 코드로 Button Type을 설정할 수 있다면 좋지 않을까요?
그래서 조사를 해봤어요.
Objective-C 시대, init 내에서
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame: frame];
if (self) {
self = [UIButtonbuttonWithType: UIButtonTypeCustom];
}
return self;
}
이런 일도 한 것 같습니다.(검증되지 않은 작업)단, Swift의 경우 self를 대입할 수 없습니다.
self = UIButton(type: .custom)
// Cannot assign to value: 'self' is immutable
그리고 button Type이라는 속성이 있습니다.buttonType = .custom
// 'buttonType' is a get-only property
읽기만 하면 혼나.여기서 나는 의문이 떠올랐다.
"코드만.custom의 하위 클래스는 어떻게 하나요?"
다음 페이지에 따르면 Swift의 UIButton 하위 클래스는 입니다.custom은 기본값입니다.
http://stackoverflow.com/questions/27079681/how-to-init-a-uibutton-subclass
검증해 봅시다.
let button = MyCustomButton()
print(button.buttonType.rawValue)
// 0
출력 0.UIButton Type의 정의 부분을 보면custom=0이 맞는 것 같습니다.
public enum UIButtonType : Int {
case custom
case system
case detailDisclosure
case infoLight
case infoDark
case contactAdd
}
이 경우 설정되지 않았기 때문에 기본값인custom이 맞습니까?안타깝게도 Button Type을 사용자 정의로 설정할 때 잊어버린 문제는 코드에서 해결할 수 없을 것 같습니다.
결론
Reference
이 문제에 관하여(Swift에는 UIButton Type이 있습니다.custom의 하위 클래스 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/keygx/items/9cda2b9bd6a4a32c2001텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)