본문 바로가기
iOS/iOS

UIButton 상태에 따른 속성 적용(storyboard)

by 패쓰킴 2022. 2. 24.
728x90

Button States 부분을 보면 버튼 상태에 따라 다르게 속성을 지정할 수 있다고 한다.

단, 텍스트 또는 이미지에 대한 속성만 state config를 통해 적용이 가능한 것 같다.

 

버튼 타입을 custom으로 바꾸면 state config 설정 칸이 생기는데

Default일때와 highlighted, selected, Disabled 상태를 선택해서 버튼 state에 따른 속성을 지정해주면 된다.

 

 

 

@interface TestViewController ()
@property (weak, nonatomic) IBOutlet UIButton * btn;
@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [_btn setSelected:NO];
}

- (IBAction)tap:(id)sender {
    [_btn setSelected:![_btn isSelected]];
}

 

Swift 예제

@IBAction func tap(_ sender: UIButton) {
  sender.isSelected.toggle()
}

 

 

참고 :

https://guides.codepath.com/ios/Configure-a-Button

https://developer.apple.com/documentation/uikit/uibutton?language=objc

https://sweetdev.tistory.com/527

 

 

728x90

'iOS > iOS' 카테고리의 다른 글

UILable cornerRadius  (0) 2022.03.16
UIView 값이 틀릴 때  (0) 2022.03.14
JSON ecdoing / decoding  (0) 2022.02.24
CustomView  (0) 2022.02.23
ERROR 모음  (0) 2022.02.17

댓글