去掉搜索框(searchBar)的背景框

使用iOS系统自带的searchBar。

_searchBar = [UISearchBar new];
_searchBar.placeholder = @"输入您想查询的内容";
_searchBar.delegate = self;
[self.view addSubview:_searchBar];
[_searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_offset(0);
    make.left.mas_offset(0);
    make.right.offset(-40);
    make.height.mas_equalTo(40);
}];

但是做出来后不是自己想要的那种效果修改背景框颜色,试了很多种方法都不太理想!用了下面的方法可以了! 

_searchBar.barTintColor = [UIColor whiteColor];

_searchBar.layer.borderWidth = 1;

_searchBar.layer.borderColor = [UIColor whiteColor].CGColor;

效果图:


修改searchbar上的输入框的样式,例如:改变搜索框中的placeholder的颜色。

UITextField *searchField = [_searchBar valueForKey:@"searchField"];
[searchField setValue:COLOR_MAIN_BG_BLUE forKeyPath:@"placeholderLabel.textColor"];// 改变搜索框中的placeholder的颜色
searchField.layer.borderColor = COLOR_TEXT_GRAY.CGColor;
searchField.layer.borderWidth = 0.5;
searchField.layer.cornerRadius = 5;

效果图:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用CSS来设置搜索框背景颜色和大小。以下是一种实现的方法: HTML结构: ```html <form action="/search" method="get" class="search-form"> <input type="text" name="query" placeholder="在此输入搜索内容" class="search-input"> <button type="submit" class="search-button">搜索</button> </form> ``` CSS样式: ```css .search-form { display: flex; justify-content: center; align-items: center; } .search-input { width: 300px; /* 设置搜索框的宽度 */ height: 40px; /* 设置搜索框的高度 */ background-color: #f2f2f2; /* 设置搜索框背景颜色 */ border: none; /* 移除搜索框的边 */ padding: 10px; /* 设置搜索框的内边距 */ font-size: 16px; /* 设置搜索框的字体大小 */ } .search-button { background-color: #4CAF50; /* 设置按钮的背景颜色 */ color: white; /* 设置按钮的文字颜色 */ border: none; /* 移除按钮的边 */ padding: 10px 20px; /* 设置按钮的内边距 */ font-size: 16px; /* 设置按钮的字体大小 */ } ``` 在上述代码中,`.search-input` 类用于设置搜索框的样式,包括宽度、高度、背景颜色、边、内边距和字体大小。你可以根据需求调整这些值。 `.search-button` 类用于设置按钮的样式,包括背景颜色、文字颜色、边、内边距和字体大小。同样,你可以根据需求调整这些值。 你可以将上述代码添加到你的CSS文件中,或者直接将其写在HTML文件的`<style>`标签中。这样就可以设置搜索框背景颜色和大小了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值