#pragma mark ---UIButton
UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom] ;
button.frame =CGRectMake(100, 100, 50, 40);
button.backgroundColor = [UIColor greenColor];
UIImage *normalImage =[UIImage imageNamed:@"panda.png"];
[button setBackgroundImage:normalImage forState:UIControlStateNormal];
UIImage * highlightImage = [UIImage imageNamed:@"111.png"];
[button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
[button setTitle:@"熊猫" forState:UIControlStateNormal];
[button setTitle:@"shane" forState:UIControlStateHighlighted];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
[_window addSubview:button];
[_window makeKeyAndVisible];
[_window release];
return YES;
}
- (void)clickButton:(UIButton *)btn
{
btn.backgroundColor =[UIColor cyanColor];
}
#pragma mark---UITextfield 文本输入框
UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 200, 30)];
textField .text = @"you are my sunshine";
textField .borderStyle =UITextBorderStyleRoundedRect;
textField .textColor =[UIColor redColor];
textField .textAlignment = NSTextAlignmentCenter;
textField .placeholder = @"请输入电话号码";
textField .enabled = YES;
textField.clearsOnBeginEditing = YES;
textField.secureTextEntry = YES;
textField.keyboardType = UIKeyboardTypeURL;
textField.returnKeyType = UIReturnKeyJoin;
UIView *inputView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 180)];
inputView.backgroundColor =[UIColor purpleColor];
UIView *inputAccessaryView = [[UIView alloc]initWithFrame:CGRectMake(0, 0 , 0, 60)];
inputAccessaryView.backgroundColor = [UIColor yellowColor];
[inputAccessaryView release];
[inputView release];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.clearButtonMode = UITextFieldViewModeAlways;
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 40, 30);
[button setBackgroundImage:[UIImage imageNamed:@"111.png"] forState:UIControlStateNormal];
textField.leftViewMode= UITextFieldViewModeAlways;
textField.leftView = button;
#warning ----设置UITextField的代理
textField.delegate = self;
[_window addSubview:textField];
[textField release];
[_window makeKeyAndVisible];
[_window release];
return YES;
}
#pragma mark ------UITextFieldDelegate方法实现
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
NSLog(@"%s",__FUNCTION__);
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"%s",__FUNCTION__);
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
NSLog(@"%s",__FUNCTION__);
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
NSLog(@"%s",__FUNCTION__);
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSLog(@"%s",__FUNCTION__);
return YES;
}
- (BOOL)textFieldShouldClear:(UITextField *)textField{
NSLog(@"%s",__FUNCTION__);
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
NSLog(@"%s",__FUNCTION__);
[textField resignFirstResponder];
return YES;
}