繁体   English   中英

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

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

我想更改UISearchBar textfield height and width 我的问题是如何在iphone UISearchBar中更改UiSearchbar height ,width , colorUitextfield Height

任何想法或建议都将受到欢迎。

您可以从xib的源代码更改文本字段的高度。 要以源代码格式打开xib,您需要右键单击xib文件,然后选择“以源代码打开”。 在该代码上搜索文本字段,并相应地更改高度。

您可以在属性检查器下的情节提要中更改颜色本身,但是要设置x,y,宽度和高度,我将使用此颜色...

首先创建您的UISearchBar对象:

'。H'

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

然后在viewdidload / appear中显示此代码

'.m'

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

在您认为必要时进行调整。

- (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