투케이2K

128. (Objective-C/objc) UIColor 사용해 red , green , blue 값 설정 및 백그라운드 색상 지정 실시 본문

Objective-C

128. (Objective-C/objc) UIColor 사용해 red , green , blue 값 설정 및 백그라운드 색상 지정 실시

투케이2K 2022. 10. 29. 10:01
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : OBJECTIVE-C

 

[소스 코드]

// MARK: - [헤더 파일에 정의 없이 : void 메소드 구현]
- (void)testMain {
    printf("\n");
    printf("==================================== \n");
    printf("[ViewController >> testMain() :: 테스트 메소드 수행] \n");
    printf("==================================== \n");
    printf("\n");

    
    // [try catch 구문 정의 실시]
    @try {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            
            // [UIColor 선언 실시 : red, green, blue 값을 사용해 원하는 색상 설정 가능]
            UIColor *uiColor = [UIColor colorWithRed:255.0f
                                            green:204.0f
                                            blue:000.0f
                                            alpha:1.0f];
            
            
            // [설정한 UIColor 사용해 배경 백그라운드 색상 지정]
            self.view.backgroundColor = uiColor;
        });

    }
    @catch (NSException *exception) {
        printf("\n");
        printf("==================================== \n");
        printf("[ViewController >> catch :: 예외 상황 확인] \n");
        printf("[name :: %s] \n", exception.name.description.UTF8String);
        printf("[reason :: %s] \n", exception.reason.description.UTF8String);
        printf("==================================== \n");
        printf("\n");
    }
}
 

[결과 출력]

 
반응형
Comments