IOS UI 학습 튜 토리 얼 설정 UITextField 각종 속성

7088 단어 IOSUIUITextField
UITextField 는 IOS 에서 자주 사용 되 는 컨트롤 로 사용자 의 입력 정 보 를 받 아들 이 고 응용 과 사용자 의 상호작용 을 완성 합 니 다.주요 속성 설정 은 다음 과 같 습 니 다.

//   textfield        
 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];
 
//      ,              
 text.borderStyle = UITextBorderStyleRoundedRect;

 typedef enum {
 UITextBorderStyleNone, 
 UITextBorderStyleLine,
 UITextBorderStyleBezel,
 UITextBorderStyleRoundedRect 
 } UITextBorderStyle;
 
//          ,                             
 text.backgroundColor = [UIColor whiteColor];
 
//    
 text.background = [UIImage imageNamed:@"dd.png"];
 
//     
 text.disabledBackground = [UIImage imageNamed:@"cc.png"];

//         ,          password
 text.placeholder = @"password";
 
//               
 text.font = [UIFont fontWithName:@"Arial" size:20.0f];
 
//      
 text.textColor = [UIColor redColor];
 
//          ,       ,              
 text.clearButtonMode = UITextFieldViewModeAlways;
 
typedef enum {
 UITextFieldViewModeNever,     
 UITextFieldViewModeWhileEditing,      
 UITextFieldViewModeUnlessEditing,         
 UITextFieldViewModeAlways     
} UITextFieldViewMode;
 
//            
 text.text = @"           ";
 
//                  
 text.secureTextEntry = YES;
 
//    
 text.autocorrectionType = UITextAutocorrectionTypeNo;
 
typedef enum {
 UITextAutocorrectionTypeDefault,   
 UITextAutocorrectionTypeNo,      
 UITextAutocorrectionTypeYes,     
} UITextAutocorrectionType;
 
//       
 text.clearsOnBeginEditing = YES; 
 
//      
 text.textAlignment = UITextAlignmentLeft;
 
//          UITextField   UIControl,        contentVerticalAlignment
 text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
 
//   YES                 .         ,        
 textFied.adjustsFontSizeToFitWidth = YES;
 
//               
 text.minimumFontSize = 20;
 
//       
 text.keyboardType = UIKeyboardTypeNumberPad;
 
typedef enum {
 UIKeyboardTypeDefault,      ,         
 UIKeyboardTypeASCIICapable,   ASCII     
 UIKeyboardTypeNumbersAndPunctuation,       ,  +*#  
 UIKeyboardTypeURL,   URL  ,  .com      URL  
UIKeyboardTypeNumberPad,        
UIKeyboardTypePhonePad,      
 UIKeyboardTypeNamePhonePad,     ,       
UIKeyboardTypeEmailAddress,                 
UIKeyboardTypeDecimalPad,              
 UIKeyboardTypeTwitter,       ,    @、#  
 UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, 
} UIKeyboardType;
 
//       
 text.autocapitalizationType = UITextAutocapitalizationTypeNone;
 
typedef enum {
 UITextAutocapitalizationTypeNone,      
 UITextAutocapitalizationTypeWords,        
 UITextAutocapitalizationTypeSentences,         
 UITextAutocapitalizationTypeAllCharacters,        
} UITextAutocapitalizationType;
 
//return      
 text.returnKeyType =UIReturnKeyDone;
 
typedef enum {
 UIReturnKeyDefault,        ,  Return
 UIReturnKeyGo,    Go     
 UIReturnKeyGoogle,
  Google     ,    
 UIReturnKeyJoin,
  Join     
 UIReturnKeyNext,
  Next     
 UIReturnKeyRoute,
  Route     
 UIReturnKeySearch,
  Search     
 UIReturnKeySend,
  Send     
 UIReturnKeyYahoo,
  Yahoo     
 UIReturnKeyYahoo,
  Yahoo     
 UIReturnKeyEmergencyCall,       
} UIReturnKeyType;
 
//    
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
typedef enum {
UIKeyboardAppearanceDefault,     ,   
UIKeyboardAppearanceAlert,        
 
} UIReturnKeyType;

//           
 text.delegate = self;
 
// textfield     
 [self.window addSubview:text];
 
//                
 UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
 text.rightView=image;
 text.rightViewMode = UITextFieldViewModeAlways; 
 
typedef enum {
 UITextFieldViewModeNever,
 UITextFieldViewModeWhileEditing,
 UITextFieldViewModeUnlessEditing,
 UITextFieldViewModeAlways
} UITextFieldViewMode;

// return       becomeFirstResponder
 
    UITextFieldDelegate  
 
text.delegate = self;   text     ,                    UITextFieldDelegate        UITextFieldDelegate    
 
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
 [text resignFirstResponder]; //   [receiver resignFirstResponder]       receiver        
 return YES;
}

      
  UITextField       ,       UITextField  ,             ,            。          CGRect  ,                。         。
 
C textRectForBounds:   //         
C drawTextInRect:    
//       .     super           ,           ,     super .
C placeholderRectForBounds:  
//          
C drawPlaceholderInRect:  
//           .     super           ,           ,     super .
C borderRectForBounds:  
//         
C editingRectForBounds:  
//         
C clearButtonRectForBounds:  
//     clearButton  ,  size    button     
C leftViewRectForBounds:
C rightViewRectForBounds:
 
    
 
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 
 
//    BOOL ,               
 
 return YES; 
} 
 
- (void)textFieldDidBeginEditing:(UITextField *)textField{ 

 //       ,       first responder 
} 
 
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{ 

//  BOOL ,              ,     ,       first responder 
 
//                  ,    NO 
 
//                        ,       
 
 return NO; 
} 
 
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ 

//           ,               ,        。 
//                     
//                ,             ,      。  
//            NO 
//           NSRange  ,           ,            
 
  return YES; 
} 
 
- (BOOL)textFieldShouldClear:(UITextField *)textField{ 
 
//    BOOL                  
//                  
 
  return YES; 
} 
 
-(BOOL)textFieldShouldReturn:(UITextField *)textField{ 
 
//    BOOL ,                  
 
//       resignFirstResponder   ,        ,       [textField resignFirstResponder];
//   resign                

  return YES; 
}

이상 은 본 고의 모든 내용 이 므 로 여러분 들 이 IOS 프로 그래 밍 을 배 우 는 데 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기