How to change the position or hide magnifier icon in UISearchBar in IOS 7?

前端 未结 3 2031
野趣味
野趣味 2021-02-02 13:15

I am working on IOS 7 application.By default its appearing like Pic(1).But I need to change it as Pic(2).I googled and found few answers for the requirement,but it has not chang

相关标签:
3条回答
  • 2021-02-02 13:36

    I'm not sure how to left-align the placeholder, but as of iOS 5.0 there's a simple, supported way to modify the search bar's text field properties, e.g.:

    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setLeftViewMode:UITextFieldViewModeNever];
    

    which will hide the magnifying glass icon.

    0 讨论(0)
  • 2021-02-02 13:37
        UITextField *txfSearchField = [looksearchbar valueForKey:@"_searchField"];
        [txfSearchField setBackgroundColor:[UIColor whiteColor]];
        [txfSearchField setLeftViewMode:UITextFieldViewModeNever];
        [txfSearchField setRightViewMode:UITextFieldViewModeNever];
        [txfSearchField setBackground:[UIImage imageNamed:@"searchbar_bgImg.png"]];
        [txfSearchField setBorderStyle:UITextBorderStyleNone];
        //txfSearchField.layer.borderWidth = 8.0f;
        //txfSearchField.layer.cornerRadius = 10.0f;
        txfSearchField.layer.borderColor = [UIColor clearColor].CGColor;
        txfSearchField.clearButtonMode=UITextFieldViewModeNever;
    

    Try this may be it will help u........

    0 讨论(0)
  • 2021-02-02 13:58

    You could try:

    searchBar.setImage(UIImage(named: "yourimage")!, forSearchBarIcon: UISearchBarIcon.Clear, state: UIControlState.Normal)
    
    0 讨论(0)
提交回复
热议问题