liebus

알림 창 - UIAlertView 만들기 본문

예전꺼(2014년이전꺼)/iOS

알림 창 - UIAlertView 만들기

리베스 2011. 3. 28. 21:53

UIAlertView 와 UIActionSheet

UIAlertView는 팝업창 이라 생각 하면 되고
 
UIActionSheet는 모달뷰 형식의 선택 메뉴 정도라 생각 하면 될듣  

사용하는 방법은 완전 비슷 한다. 

UIAlertViewDelegate 또는 UIActionSheetDelegate 를 Protocol로 선언한다. 


 UIAlertView *av = [[UIAlertView alloc]
     initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Cancel"
                   
                          otherButtonTitles:@"Ok", nil];

        [av setTitle:@"Hidden Memo"]; 

        [av show]; 
        [av release];  


와 같이 보인다.  

물론 위의 그림은 UIAlertView에 UITextField를 붙여 넣은 그림 이고 위의 코드 같이 했을 경우에는
TextField가 없는 Alert창이 보인다.

버튼 클릭 이벤트는 
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
(NSInteger )buttonIndex { }
에서 처리  




UIActionSheet *voiceMenu = [[UIActionSheet alloc] initWithTitle:nil
   
delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"녹음 하기"
                                           
otherButtonTitles:@"파일 선택", nil]; 

    

    [voiceMenu showInView:self.view]; 

    [voiceMenu release];

와 같이 보여 진다.  

버튼을 클릭했을 때 전달된 이벤트는 

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {  }
에서 처리 한다.  




- 추가 UIAlertView에 UITextFile 붙이기

   //AlertView를 생성하고 
1.  UIAlertView *avRecored = [[UIAlertView alloc] initWithTitle:nil message:nil
                            
delegate:self cancelButtonTitle:ALERT_CANCEL
                            
otherButtonTitles:ALERT_OK, nil]; 

   
   
//TextFile를 생성하고 - 생성하면서 위치와 크기를 잡아 준다.
   //AlertView안에 위치를 고려
     

   UITextField *alertViewTextField = [[UITextField alloc]
                                                  initWithFrame:CGRectMake(12.0f, 70.0f, 260.0f, 26.0f)];

   //TextFile를 의 스타일을 잡고 
   alertViewTextField.
borderStyle = UITextBorderStyleRoundedRect

   alertViewTextField.clearButtonMode = UITextFieldViewModeWhileEditing

   alertViewTextField.keyboardAppearance = UIKeyboardAppearanceAlert

   alertViewTextField.autocapitalizationType =
                                             UITextAutocapitalizationTypeWords

   alertViewTextField.autocorrectionType = UITextAutocorrectionTypeNo

   alertViewTextField.contentVerticalAlignment =
                                      UIControlContentVerticalAlignmentCenter 


   [avRecored setTitle:@"Game over"]; 
   
[avRecored setMessage:[[self.lbTime text] stringByAppendingFormat:@"\n\n"]]; 
   
   //AlertView의 위치를 잡아주고 

   [avRecored setTransform:CGAffineTransformMakeTranslation(0.0, 0.0)];

   //일케 해도 되더라 
   //CGRect
 bounds = av.bounds
   //alertViewTextField.center = CGPointMake(bounds.size.width / 2.0f,
                                         bounds.size.height / 2.0f - 10.0f);


   [avRecored addSubview:alertViewTextField]; 
   [avRecored show];         

   [avRecored release]; 
   
   //키보드를 불러온다.
   [alertViewTextField becomeFirstResponder];  


출처 - 나

 

Comments