更改UISearchBar TextField的帧大小?

时间:2014-02-03 06:23:21

标签: ios iphone ipad uisearchbar

我无法设置UISearchBarTextField的框架....我应该创建自己的搜索栏还是有办法执行上述操作?

https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UISearchBarTextField.h

2 个答案:

答案 0 :(得分:2)

在iOS 7中

访问文本字段,你必须在更多级别上重申。像这样改变你的代码

for (UIView *subView in self.searchBar.subViews){
    for (UIView *2ndLeveSubView in subView.subViews){
    if ([2ndLeveSubView isKindOfClass:[UITextField class]])
        {
            searchBarTextField = (UITextField *)2ndLeveSubView;

            break;
        }
    }
   }

但是,清除UISearchBar的后台并在文本字段中设置搜索栏图标的最佳方法是:

[searchBar setBackgroundImage:[[UIImage alloc] init] ];//if you want to remove background of uisearchbar
UIImage *image = [UIImage imageNamed: @"search_icon.png"];
[searchBar setImage:image forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

答案 1 :(得分:-4)

你试过吗?

 [searchBarObj setFrame:CGRectMake(44, 0, 320 - 44, 43)];