/**
* 自定义导航搜索框事件
*/
- (void)initNavSearch{
UIColor *color = self.navigationController.navigationBar.barTintColor;
_searchBar = [[UISearchBar alloc] init];
_searchBar.delegate = self;
_searchBar.frame = CGRectMake(self.view.frame.size.width - 110,(44 - 20) / 2,100,20);
_searchBar.backgroundColor = color;
_searchBar.layer.cornerRadius = 3;
_searchBar.layer.masksToBounds = YES;
[_searchBar.layer setBorderColor:[UIColor whiteColor].CGColor];
//设置边框为白色
[self.navigationController.navigationBar addSubview:_searchBar];
}
显示结果:
本文介绍了一种自定义导航栏搜索框的方法,通过使用UIKit框架中的UISearchBar组件,并设置了其代理、位置、颜色等属性,实现了iOS应用中美观且实用的搜索功能。
9万+

被折叠的 条评论
为什么被折叠?



