Nic*_*lis 41
在iOS 5.0+中,您可以使用自定义搜索栏图像
- (void)setImage:(UIImage *)iconImage forSearchBarIcon:(UISearchBarIcon)icon state:(UIControlState)state
Run Code Online (Sandbox Code Playgroud)
在UISearchBar的特定实例中或使用UIAppearance
代理的一堆实例.
Jef*_*eff 12
要完全删除图标,可以使用以下代码行:
Objective-C的:
// Remove the icon, which is located in the left view
[UITextField appearanceWhenContainedIn:[UISearchBar class], nil].leftView = nil;
// Give some left padding between the edge of the search bar and the text the user enters
[UISearchBar appearance].searchTextPositionAdjustment = UIOffsetMake(10, 0);
Run Code Online (Sandbox Code Playgroud)
迅速:
// Remove the icon, which is located in the left view
UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).leftView = nil
// Give some left padding between the edge of the search bar and the text the user enters
UISearchBar.appearance().searchTextPositionAdjustment = UIOffsetMake(10, 0)
Run Code Online (Sandbox Code Playgroud)
Ros*_*lav 11
// hide magnifying glass
UITextField* searchField = nil;
for (UIView* subview in searchBar.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField*)subview;
break;
}
}
if (searchField) {
searchField.leftViewMode = UITextFieldViewModeNever;
}
Run Code Online (Sandbox Code Playgroud)
这隐藏了放大镜.效果很好.
Cip*_*rau 10
在swift 2.0中这样做:
let textFieldInsideSearchBar = self.searchBar.valueForKey("searchField") as! UITextField
textFieldInsideSearchBar.leftViewMode = UITextFieldViewMode.Never
Run Code Online (Sandbox Code Playgroud)
Swift 4解决方案
searchBar.setImage(UIImage(), for: .search, state: .normal)
Run Code Online (Sandbox Code Playgroud)
小智 6
如何在IOS 7中更改UISearchBar中的位置或隐藏放大镜图标?
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setLeftViewMode:UITextFieldViewModeNever];
Run Code Online (Sandbox Code Playgroud)
Swift 4解决方案:
searchBar.setImage(UIImage(), for: .search, state: .normal)
Run Code Online (Sandbox Code Playgroud)
您可能还需要调整左侧的间隙:
searchBar.setPositionAdjustment(UIOffset(horizontal: -20, vertical: 0), for: .search)
Run Code Online (Sandbox Code Playgroud)
或者在Swift 4.0中简单的单行:
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).leftViewMode = .never
Run Code Online (Sandbox Code Playgroud)
注意:这将从UITextFields
包含在其中的所有内容中删除左手图标UISearchBars
.
小智 5
您可以使用
searchBar.setImage(UIImage(), for: .search, state: .normal)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22791 次 |
最近记录: |