输入框和分割线

上图!

224641_dVBB_2618362.png

顶部的输入框和按钮下部的分割线,具体实现代码如下:

- (void)setUpNav{

   

     //设置放大镜

    UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"-15"]];

    

    //设置输入框

    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(5, 5, 260, 40)];

    self.searchTextField = textField;

    //放大镜放入输入框中

    textField.rightView = img;

    textField.rightViewMode = UITextFieldViewModeAlways;

    textField.backgroundColor = [UIColor whiteColor];

    textField.placeholder = @"输入医院名称查找";

    textField.clearButtonMode = UITextFieldViewModeWhileEditing;

    textField.layer.cornerRadius = 5;

    self.navigationItem.titleView = textField;

    


}

//添加按钮

- (UIView *)setUpHeaderView {

    UIView * header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 60)];

    

    

    //左按钮

    UIButton *leftBtn = [[UIButton alloc]init];

    //文字

    [leftBtn setTitle:@"医院等级" forState:UIControlStateNormal];

    //颜色

    [leftBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];

   //小箭头

    [leftBtn setImage:[UIImage imageNamed:@"arrow"] forState:UIControlStateNormal];

    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 160, 0, 0);

    

    [header addSubview:leftBtn];

    //右按钮

    UIButton *rightBtn = [[UIButton alloc]init];


    [rightBtn setTitle:@"医院地区" forState:UIControlStateNormal];

    [rightBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];

    [rightBtn setImage:[UIImage imageNamed:@"arrow"] forState:UIControlStateNormal];

    rightBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 160, 0, 0);

    //分割线

    UIView *line = [[UIView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2 , 10, 1, 30)];

    line.backgroundColor = [UIColor grayColor];

    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(0, 50, [UIScreen mainScreen].bounds.size.width, 1)];

    line2.backgroundColor = [UIColor grayColor];

    

    [header addSubview:rightBtn];

    [header addSubview:line];

    [header addSubview:line2];

    

    //添加约束

    [leftBtn makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(header.mas_top);

        make.left.equalTo(header.mas_left);

        make.bottom.equalTo(header.mas_bottom);

        make.right.equalTo(header.mas_left).offset([UIScreen mainScreen].bounds.size.width/2);

    }];

    [rightBtn makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(header.mas_top);

        make.right.equalTo(header.mas_right);

        make.bottom.equalTo(header.mas_bottom);

        make.left.equalTo(header.mas_left).offset([UIScreen mainScreen].bounds.size.width/2);

    }];

    [leftBtn addTarget:self action:@selector(BtnClick) forControlEvents:UIControlEventTouchUpInside];

    return header;

}


转载于:https://my.oschina.net/u/2618362/blog/664724

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值