CGFloat enterW = self.view.frame.size.width - 80;// 245;
CGFloat y = 0;
containerView = [[UIView alloc] initWithFrame:CGRectMake(0, y, self.view.frame.size.width, 40)];
[self.view addSubview:containerView];
textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 5, enterW-10, 30)];
textField.font = [UIFont systemFontOfSize:18.0f];
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing; //显示一次性删除按钮
textField.backgroundColor = [UIColor whiteColor];
textField.layer.borderWidth = 1.0;
textField.layer.cornerRadius = 5.0;
textField.layer.borderColor = [UIColor lightGrayColor].CGColor; //显示边框颜色
textField.leftViewMode = UITextFieldViewModeAlways;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //控件居中
textField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchIcon"]];
textField.leftView.contentMode=UIViewContentModeCenter; //显示左边放大镜
textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[containerView addSubview:textField];
UIButton *uploadBtn = [[UIButton alloc] init];
uploadBtn.frame = CGRectMake(self.view.frame.size.width - 70 - 5, 5, 70, 30);
[uploadBtn setTitle:@"搜索" forState:UIControlStateNormal];
[uploadBtn successStyle];
[uploadBtn addTarget:self action:@selector(uploadBtnPressed) forControlEvents:UIControlEventTouchUpInside];
[containerView addSubview:uploadBtn];
[containerView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
NSLog(@"containerView y %f", containerView.frame.origin.y);