UISearchBar去掉SearchBar上面两条分割线
2024-09-05 12:05:27
设置之前:
设置之后:
代码如下:
//
// ViewController.m
// UISearchBarDemo
//
// Created by 思 彭 on 17/3/24.
// Copyright © 2017年 思 彭. All rights reserved.
// #import "ViewController.h" @interface ViewController ()<UISearchBarDelegate> @property (nonatomic, strong) UISearchBar *searchBar;/**<搜索框 */ @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
self.title = @"UISearchBar";
[self setupSearchBar];
[self setSearchBar];
} //添加搜索框
- (void)setupSearchBar { self.searchBar = [[UISearchBar alloc]init];
self.searchBar.frame = CGRectMake(, , self.view.frame.size.width, );
self.searchBar.delegate = self;
// self.searchBar.searchBarStyle =UISearchBarStyleMinimal;
self.searchBar.barTintColor = [UIColor colorWithRed:238.0/ green:238.0/ blue:238.0/ alpha:1.0]; // 去除了分割线,需要设置背景颜色
self.searchBar.backgroundColor = [UIColor colorWithRed:238.0/ green:238.0/ blue:238.0/ alpha:1.0];
[self.searchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone];
self.searchBar.placeholder = @"搜索";
[self.searchBar sizeToFit];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
[self.navigationController.navigationBar addGestureRecognizer:tap];
[self.view addSubview:self.searchBar];
} // 去掉SearchBar上面两条线
- (void)setSearchBar { for (UIView *obj in [self.searchBar subviews]) {
for (UIView *objs in [obj subviews]) {
if ([objs isKindOfClass:NSClassFromString(@"UISearchBarBackground")]){
[objs removeFromSuperview];
}
}
if ([obj isKindOfClass:NSClassFromString(@"UISearchBarBackground")]){
[obj removeFromSuperview];
}
}
} #pragma marl - UISearchBarDelegate - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { self.searchBar.showsCancelButton = YES;
return YES;
} - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { self.searchBar.showsCancelButton = NO;
searchBar.text = @"";
[self.searchBar resignFirstResponder];
} - (void)tapClick:(UITapGestureRecognizer *)tap { self.searchBar.showsCancelButton = NO;
[self.searchBar resignFirstResponder];
} //点击搜索按钮
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { self.searchBar.showsCancelButton = NO;
[searchBar resignFirstResponder];
} @end
最新文章
- 在你的ASP.NET MVC中使用查找功能
- sed教程
- 全国高校网安联赛Web专场~WriteUp
- (转)LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION
- Node.js与Sails~Model和ORM的持久化
- nginx作为负载均衡服务器——测试
- 几张图弄明白ios布局中的尺寸问题
- vector族函数
- javascript 中的 call
- The version of CocoaPods used to generate the lockfile (*) is higher than the version of the current executable (*). Incompatibility issues may arise.
- C# .NET3.5 改为 到.NET2.0 时 TypedTableBase 报错解决方法
- CSS3实现图片鼠标悬浮放大效果
- STM32F4系列单片机上使用CUBE配置MBEDTLS实现pem格式公钥导入
- 我的DIY作品
- 腾讯云主机安装登录mysql失败--解决方案[重置root密码并实现远程连接]
- 嵌入式开发之uart---编程
- 如何在忘记mysql的登录密码时更改mysql登录的密码(window及linux)
- Linux命令行上执行操作,不退回命令行的解决方法
- hdoj2111 Saving HDU
- 实现qsort(和qsort差一个数量级啊,伤自尊了)