加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 自定义搜索栏

发布时间:2020-12-15 01:40:18 所属栏目:百科 来源:网络整理
导读:我正在设计一个搜索栏.我需要搜索栏看起来像图像中的一个.试过几种但没有变化的方法.非常感谢 将帖子 使用Richards代码后看到图像,它看起来像这样.我希望灰色是清晰的 解决方法 self.searchBar是一个IBOutlet.您也可以动态创建它. self.searchBar.layer.bord
我正在设计一个搜索栏.我需要搜索栏看起来像图像中的一个.试过几种但没有变化的方法.非常感谢

enter image description here

将帖子
使用Richards代码后看到图像,它看起来像这样.我希望灰色是清晰的

解决方法

self.searchBar是一个IBOutlet.您也可以动态创建它.

self.searchBar.layer.borderWidth = 2.0;
self.searchBar.layer.borderColor = [UIColor brownColor].CGColor;
self.searchBar.layer.cornerRadius = 15.0;
self.searchBar.barTintColor = [UIColor colorWithRed:255/255.0 green:246/255.0 blue:241/255.0 alpha:1.0];
self.searchBar.backgroundColor = [UIColor clearColor];

UITextField *textField = [self.searchBar valueForKey:@"_searchField"];
textField.textColor = [UIColor brownColor];
textField.placeholder = @"Search";
textField.leftViewMode = UITextFieldViewModeNever; //hiding left view
textField.backgroundColor = [UIColor colorWithRed:255/255.0 green:246/255.0 blue:241/255.0 alpha:1.0];
textField.font = [UIFont systemFontOfSize:18.0];
[textField setValue:[UIColor brownColor] forKeyPath:@"_placeholderLabel.textColor"];

UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0,20,30)];
imgview.image = [UIImage imageNamed:@"searchIcon.png"]; //you need to set search icon for textfield's righ view

textField.rightView = imgview;
textField.rightViewMode = UITextFieldViewModeAlways;

输出:

enter image description here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读