1
사용자 정의 컨트롤을 생성했으며 @IBInspectable 속성에 액션을 전달하여 UIButton을 사용하여 @IBAction을 설정하는 것과 동일한 효과를 얻고 싶습니다. 어떻게해야합니까?Swift 3의 IBInspectable을 통한 전달 선택기
class MyControl: UIButton {
// Problem with this string approach is
//I have no way to know which instance to perform the selector on.
@IBInspectable var tapAction: String?
// set up tap gesture
...
func labelPressed(_ sender: UIGestureRecognizer) {
if let tapAction = tapAction {
// How should I convert the string in tapAction into a selector here?
//I also want to pass an argument to this selector.
}
}
}
'tapAction' 변수가 어떻게 설정되어 있는지 궁금하십니까? 나는'tapAction' 값을 바꾸는 원인이 무엇인가요? – user1046037
인터페이스 빌더에서 설정 중입니다. – Boon
스위치 케이스를 사용하여 일련의 문자열 값을 기반으로 적절한 선택기를 설정하십시오. 제 개인적인 견해로는'IBInspectable' 변수를 사용하는 대신 프로그래밍 방식으로 훨씬 쉽게 할 수 있습니다. – user1046037