2016-08-11 2 views
0

UIButton을 선택하면 문제가 있습니다.UIButton 선택한 이미지가 작동하지 않습니다.

radioButton.isSelected = true 의해 선택되어
let radioButton = UIButton(type: .system) 
radioButton.frame = CGRect(x: 0, y: 0, width: 40, height: 40) 
radioButton.setImage(UIImage(named: "buttonUnchecked"), for: .normal) 
radioButton.setImage(UIImage(named: "buttonChecked"), for: .selected) 
radioButton.setTitle("This is some text.", for: .normal) 
radioButton.sizeToFit() 

, 이미지가 도시되지 않는다 : 코드 스위프트 3이다.

+2

의? –

+0

보기에 radioButton을 추가 했습니까? – penatheboss

답변

0

radioButton.addTarget(self, action: "addMethodName", forControlEvents: UIControlEvents.TouchUpInside) 

같은 대상을 추가하는 방법으로이 같은 이미지를 변경을 시도 할 수 있습니다 :

radioButton.setImage(UIImage(named: "buttonUnchecked"), for: .normal) 
+0

예, "선택됨"상태를 사용하지 않으면 가능합니다. 하지만 단추 레이블의 기본 색이 배경 때문에 사용하고 싶습니다. 더 많은 아이디어가 있습니까? ;) – Heiko

0

당신은 아마 사용자 정의 버튼 대신 시스템 형의 형태 사용해야합니다. 이 시도 :

let radioButton = UIButton(type: .Custom) 

대신 이미지가`buttonChecked`이 오타없이 존재한다는 것을 확인 했

let radioButton = UIButton(type: .system) 
관련 문제