2014-05-13 38 views

回答

2

您需要自定義搜索器,而不是您已經使用。

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; 

試試這個。

+1

這似乎只是使圖標在iOS7和iOS8上消失,而不是左對齊。 – ghr

+0

對於Swift-3請參閱http://stackoverflow.com/questions/19289406/uisearchbar-search-icon-isnot-left-aligned-in-ios7/41976067#41976067 – Shrawan