码迷,mamicode.com
首页 > 其他好文 > 详细

新建搜索bar

时间:2015-08-19 11:07:09      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

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);

 

新建搜索bar

标签:

原文地址:http://www.cnblogs.com/zhoup/p/4741484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!