UIButton及点击按钮键盘回收

UIButton

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    // UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];    

    button.frame = CGRectMake(100, 100, 100, 30);
    button.backgroundColor = [UIColor blueColor];
    
    // 设置button的title
    // 不同模式(不点击)
    [button setTitle:@"登陆" forState:UIControlStateNormal];
    // 处于高亮状态 (点击时)
    [button setTitle:@"哈哈" forState:(UIControlStateHighlighted)];
    // 设置title颜色        
    [button setTitleColor:[UIColor yellowColor] forState:(UIControlStateNormal)];
  
   // 设置按钮边框宽度
   [button.layer setBorderWidth:1.0];
   // 设置按钮四个角的圆弧半径
   button.layer.cornerRadius = 10.0;
// 如果给button添加图片,button的样式要用custom样式的 因为system会对图片进行渲染 // [button setImage:[UIImage imageNamed:@"1"] forState:(UIControlStateNormal)]; [button setBackgroundImage:[UIImage imageNamed:@"1"] forState:(UIControlStateNormal)];

UIButton相应点击事件

  @selector(haha:)对应方法名,事件行为(键盘回收)

{
...
  [button addTarget:self action:@selector(haha:) forControlEvents:UIControlEventTouchUpInside];
...
}
- (void)haha:(UIButton *)test
{
  // 四个方式 // 一.设置textField的enabled属性为NO。 //找到编译窗口 UITextField *textField = self.window.subviews[0]; textField.enabled = !textField.enabled; // 二.让textField处于非编辑状态 [textField endEditing:YES]; // 三.让textField取消第一响应者 [textField resignFirstResponder]; // [textField becomeFirstResponder];// 成为第一响应者 // 四.让window处于非编辑状态 [self.window endEditing:YES]; }

  

点击按钮键盘回收  

posted @ 2015-08-22 16:46  誓言の真嗳  阅读(2134)  评论(0编辑  收藏  举报