我刚刚放置了一个带有表格视图的搜索栏控制器。现在它看起来像这样的正常搜索栏: 如何将正常的搜索栏更改为下方的图像,如搜索栏
像圆润搜索图标应该显示在过去,当我按下搜索,取消按钮会自动应显示。
现在通过使用代码,是否有可能做这些更改。请帮助我。如何获得像上面的图像。
我使用SWIFT 2.0
我刚刚放置了一个带有表格视图的搜索栏控制器。现在它看起来像这样的正常搜索栏: 如何将正常的搜索栏更改为下方的图像,如搜索栏
像圆润搜索图标应该显示在过去,当我按下搜索,取消按钮会自动应显示。
现在通过使用代码,是否有可能做这些更改。请帮助我。如何获得像上面的图像。
我使用SWIFT 2.0
采取的UIView作为containerView您的文本框,只要你想设置它的背景色。
将角落半径设置为textField并为其添加一些填充。
角半径:
夫特:
let textFieldSearchBar = UITextField()
textFieldSearchBar.layer.masksToBounds = true
textFieldSearchBar.layer.cornerRadius = 5.2
textFieldSearchBar.layer.borderColor = UIColor.lightGrayColor().CGColor
textFieldSearchBar.layer.borderWidth = 1.5
目标c:
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;
目标c:
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;
目标c:
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
我创造了如下自定义搜索BAS:
希望这会帮助你。
感谢您的回答,如果可能的话,您可以将它作为swift 2.0。因为我开始使用swift ios 2.0 – user5513630
查看Swift的更新代码。 –
我试过这段代码,我在填充左侧和右侧的paddingWidth中发生了一些错误 – user5513630
定制一个:)。改用textField。 –
uitext字段??如果我为搜索放置任何图像图标,那么当我按搜索时如何获取该取消按钮。你能举一些例子吗? – user5513630