Ios 如何将普通搜索栏更改为类似图像的搜索栏
我刚刚放置了一个带有表视图的搜索栏控制器。现在它看起来像普通的搜索栏,如下所示: 但我需要将此搜索栏更改为下图所示的内容: 像圆角和搜索图标应该显示在最后,当我按下搜索,取消按钮应该自动显示 现在,通过使用代码,可以进行这些更改。请帮帮我。如何得到像上面的图片 我正在使用swift 2.0Ios 如何将普通搜索栏更改为类似图像的搜索栏,ios,iphone,swift,Ios,Iphone,Swift,我刚刚放置了一个带有表视图的搜索栏控制器。现在它看起来像普通的搜索栏,如下所示: 但我需要将此搜索栏更改为下图所示的内容: 像圆角和搜索图标应该显示在最后,当我按下搜索,取消按钮应该自动显示 现在,通过使用代码,可以进行这些更改。请帮帮我。如何得到像上面的图片 我正在使用swift 2.0 将UIView作为文本字段的containerView,根据需要设置其背景色 将“拐角半径”设置为文本字段,并为其添加一些填充 角半径: Swift: 目标-c: 左填充: Swift: 目标-c: 右填
希望这对你有帮助 定制一个:)。改为使用文本字段。uitext字段??如果我放置了任何用于搜索的图像图标,那么当我按下搜索时如何获得取消按钮。你能举个例子吗?谢谢你的回答,如果可能的话,你能为swift 2.0做一个例子吗。因为我是从swift ios 2.0开始的,我已经尝试过这段代码,我在左右填充的
paddingWidth
中遇到了一些错误您遇到了什么错误?您是否尝试过提供一些宽度作为UIView*leftPaddingView=[[UIView alloc]initWithFrame:CGRectMake(0,0,20,20)];
let textFieldSearchBar = UITextField()
textFieldSearchBar.layer.masksToBounds = true
textFieldSearchBar.layer.cornerRadius = 5.2
textFieldSearchBar.layer.borderColor = UIColor.lightGrayColor().CGColor
textFieldSearchBar.layer.borderWidth = 1.5
textFieldSearchBar.layer.cornerRadius = 5.2f;
textFieldSearchBar.layer.borderColor = kTextFieldBorderColor.CGColor;
textFieldSearchBar.layer.borderWidth = 1.5f;
let leftPaddingView = UIView(frame: CGRect(x: 0, y: 0, width: paddingWidth, height: 20))
textFieldSearchBar.leftView = leftPaddingView
textFieldSearchBar.leftViewMode = UITextFieldViewMode.Always;
UIView *leftPaddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, paddingWidth, 20)];
textFieldSearchBar.leftView = leftPaddingView;
textFieldSearchBar.leftViewMode = UITextFieldViewModeAlways;
let rightPaddingView = UIView(frame: CGRect(x: 0, y: 0, width: paddingWidth, height: 20))
textFieldSearchBar.rightView = rightPaddingView
textFieldSearchBar.rightViewMode = UITextFieldViewMode.Always;
UIView *rightPaddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
textFieldSearchBar.rightView = rightPaddingView;
textFieldSearchBar.rightViewMode = UITextFieldViewModeAlways;
buttonSearch.setBackgroundImage(UIImage(named: "magnifyingGlass"), forState: UIControlState.Normal)
buttonSearch.setBackgroundImage(UIImage(named: "crossButton"), forState: UIControlState.Selected)
//Show magnifying glass image
buttonSearch.selected = false
//Show cross button image
buttonSearch.selected = true