简体   繁体   English

如何在iPhone的UISearchBar中更改UiSearchbar的高度,宽度,颜色和Uitextfield高度?

[英]How to change the UiSearchbar height ,width , color and Uitextfield Height in UISearchBar in iphone?

I Want to change UISearchBar .The textfield height and width . 我想更改UISearchBar textfield height and width My question is how to change the UiSearchbar height ,width , color and Uitextfield Height in UISearchBar in iphone ? 我的问题是如何在iphone UISearchBar中更改UiSearchbar height ,width , colorUitextfield Height

Any Idea or Suggestions would be welcome. 任何想法或建议都将受到欢迎。

You can change the height of the textfield from the source code of the xib. 您可以从xib的源代码更改文本字段的高度。 For opening a xib in source code format you need to right click on the xib file and then select "Open as source code". 要以源代码格式打开xib,您需要右键单击xib文件,然后选择“以源代码打开”。 On that code search for the textfield and change the height accordingly. 在该代码上搜索文本字段,并相应地更改高度。

You can change the color itself in storyboard under attributes inspector, however, to set the x,y,width & height I use this... 您可以在属性检查器下的情节提要中更改颜色本身,但是要设置x,y,宽度和高度,我将使用此颜色...

Firstly create your UISearchBar object: 首先创建您的UISearchBar对象:

'.h' '。H'

@property (strong, nonatomic) IBOutlet UISearchBar *searchBar;

And then in the viewdidload/willappear put this code 然后在viewdidload / appear中显示此代码

'.m' '.m'

self.searchBar.frame = CGRectMake(34, 244.5, 306, 30);

Make adjustments as you deem necessary. 在您认为必要时进行调整。

- (void)setSearchIconToFavicon 
{
    // Really a UISearchBarTextField, but the header is private.
[[mySearchBar.subviews objectAtIndex:0] setAlpha:0.0];

UITextField *searchField = nil;`enter code here`
for (UIView *subview in mySearchBar.subviews) 
{
    if ([subview isKindOfClass:[UITextField class]]) 
    {
        searchField = (UITextField *)subview;
        break;
    }
}
if(!(searchField == nil)) 
{
    searchField.textColor = [UIColor blackColor];
    [searchField setBackground: [UIImage imageNamed:@"searchFieldBG.png"] ];
    [searchField setBorderStyle:UITextBorderStyleNone];
    searchField.frame = CGRectMake(4, 5, 285, 50); 
}
}
[searchBar setFrame:CGRectMake(0,0,80,30)];

希望它对您有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM