본문으로 바로가기

iOS alert (메시지 창)

category [ 모바일 관련 ]/아이폰(iOS) 2018. 11. 6. 11:47

[self alertViewPlay:@"제목" Msg:@"내용" noBtn:NO Close:YES];




/*===================================

 메시지 노출 START

 ===================================*/

- (void) alertViewPlay:(NSString *)title Msg:(NSString *)msg noBtn:(BOOL)nobtn Close:(BOOL)close

{

    

    

    UIAlertController * alert = [UIAlertController

                                 alertControllerWithTitle:title

                                 message:msg

                                 preferredStyle:UIAlertControllerStyleAlert];

    

    

    UIAlertAction* yesButton = [UIAlertAction

                                actionWithTitle:@"확인"

                                style:UIAlertActionStyleDefault

                                handler:^(UIAlertAction * action) {

                                    if(close){

                                        //Handle your yes please button action here

                                        [self dismissViewControllerAnimated:YES completion:nil];

                                    }

                                }];

    [alert addAction:yesButton];

    

    

    if(nobtn){

        UIAlertAction* noButton = [UIAlertAction

                                   actionWithTitle:@"취소"

                                   style:UIAlertActionStyleDefault

                                   handler:^(UIAlertAction * action) {

                                       // Handle no, thanks button

                                   }];

        [alert addAction:noButton];

    }

    

    

    [self presentViewController:alert animated:YES completion:nil];

    

}

/*===================================

 메시지 노출 END

 ===================================*/