iphone – 目标c中UINavigationBar右侧的UISearchBar

iphone – 目标c中UINavigationBar右侧的UISearchBar,第1张

概述我创建了一个iPad应用程序,我希望将searchBar放在导航栏的右侧. 当我在导航栏中添加搜索栏时,它位于navigationBar的中间位置.在中间,相反,我想显示一个特定的图像. 我怎样才能做到这一点? 这是我的代码片段, [self.navigationController.navigationBar setTintColor:[[UIColor alloc]initWithRed:15 我创建了一个iPad应用程序,我希望将searchbar放在导航栏的右侧.

当我在导航栏中添加搜索栏时,它位于navigationbar的中间位置.在中间,相反,我想显示一个特定的图像.

我怎样才能做到这一点?

这是我的代码片段,

[self.navigationController.navigationbar setTintcolor:[[UIcolor alloc]initWithRed:150.0 / 255 green:22.0 / 255 blue:22.0 / 255 Alpha:0.0]];UIImage *image = [UIImage imagenamed:@"logo(1).png"];UIImageVIEw *imageVIEw = [[UIImageVIEw alloc] initWithImage:image];[self.navigationItem setTitleVIEw:imageVIEw];self.navigationItem.TitleVIEw = sbar;[TitleVIEw release];

使用上面的代码,我只能在模拟器中看到searchbar(位于中间).

解决方法 试试这个:

UISearchbar *searchbar = [[[UISearchbar alloc] initWithFrame:CGRectMake(0,100,40)] autorelease];searchbar.backgroundImage = [[[UIImage alloc] init] autorelease];self.navigationItem.rightbarbuttonItem = [[[UIbarbuttonItem alloc] initWithCustomVIEw:searchbar] autorelease];

您可以随时更改框架.请记住,backgroundImage属性仅在iOS 5中可用.您应该搜索替代选项以摆脱iOS 4.x的背景

如果这对您有用,请告诉我.

总结

以上是内存溢出为你收集整理的iphone – 目标c中UINavigationBar右侧的UISearchBar全部内容,希望文章能够帮你解决iphone – 目标c中UINavigationBar右侧的UISearchBar所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1078991.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存