按钮相关属性设置(按钮文字位置 和图片位置设置)

- (UIButton *)navSearBtn
{
    if (!_navSearBtn) {
        _navSearBtn = [[UIButton alloc]init];
        _navSearBtn.backgroundColor = [UIColor clearColor];
        _navSearBtn.titleLabel.font = DEF_FontSize_14;
        [_navSearBtn setTitle:@"请输入关键词搜索" forState:UIControlStateNormal];
        [_navSearBtn setImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
        [_navSearBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -330 / WIDTH_6S_SCALE)];
        //按钮中文字靠最左边
//        _navSearBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        //根据需求调整按钮中文字位置
        [_navSearBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -120 / WIDTH_6S_SCALE, 0, 0)];
        _navSearBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _navSearBtn.layer.borderWidth = 1;
        [_navSearBtn addTarget:self action:@selector(navSearBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        _navSearBtn.layer.cornerRadius = 5 / HEIGHT_6S_SCALE;
        _navSearBtn.layer.masksToBounds = YES;
    }
    return _navSearBtn;
}

相关推荐