輸入框和分割線

上圖!ide

頂部的輸入框和按鈕下部的分割線,具體實現代碼以下:spa

- (void)setUpNav{3d

   

     //設置放大鏡orm

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

    

    //設置輸入框it

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

    self.searchTextField = textField;select

    //放大鏡放入輸入框中im

    textField.rightView = img;margin

    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;

}

相關文章
相關標籤/搜索