투케이2K

39. (Objective-C/objc) Button 버튼 객체 생성 , 클릭 이벤트 정의 및 배경 이미지 (setBackgroundImage) 변경 실시 본문

Objective-C

39. (Objective-C/objc) Button 버튼 객체 생성 , 클릭 이벤트 정의 및 배경 이미지 (setBackgroundImage) 변경 실시

투케이2K 2022. 7. 4. 18:14

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : OBJECTIVE-C

 

[방법 설명]

 

[헤더 [h] : 소스 코드]

#import <UIKit/UIKit.h>

@interface SettingView : UIView
{

}


// MARK: [초기 뷰 설정 메소드]
- (void) setView;


// MARK: [생체 인증 버튼 객체 설정 및 이벤트 지정]
@property (nonatomic, strong) IBOutlet UIButton* btn_finger;
-(IBAction)buttonClicked_finger:(id)sender;
 
@end
 

[몸체 [m] : 소스 코드]

#import "SettingView.h"

@implementation SettingView

@synthesize btn_finger; // MARK: [생체 인증 버튼]

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"SettingView" owner:self options:nil];
        self = [nibs objectAtIndex:0];
    }
    return self;
}





// MARK: - [초기 뷰 화면 설정]
- (void) setView
{
    printf("\n");
    printf("==================================== \n");
    printf("[SettingView :: setView :: %s] \n", "액티비티 뷰 화면 표시 실시");
    printf("==================================== \n");
    printf("\n");
    
    
    // MARK: [생체인증 프리퍼런스에 저장된 데이터 확인 및 배경 이미지 초기 설정]
    [btn_finger setBackgroundImage:[UIImage imageNamed:@"toggleon.png"] forState:UIControlStateNormal];
}





// MARK: - [생체 인증 버튼 클릭 이벤트 정의]
-(IBAction)buttonClicked_finger:(id)sender{
    printf("\n");
    printf("==================================== \n");
    printf("[SettingView :: buttonClicked_finger :: %s] \n", "지문인증 버튼 클릭 이벤트 발생");
    printf("==================================== \n");
    printf("\n");
    
    
    // [버튼 배경 이미지 변경]
    [sender setBackgroundImage:[UIImage imageNamed:@"toggleff.png"] forState:UIControlStateNormal];
}


@end

 

반응형
Comments