【发布时间】:2011-10-04 13:18:00
【问题描述】:
我正在 iphone 中开发一个应用程序。我必须在我的视图或 UINavigation 栏上添加图像。我的条件是图像将部分添加到导航栏,部分添加到视图中。
我已将它作为条形按钮项添加到标题视图中,但它的高度受条形高度的限制。我需要它放在导航栏下方。
如何实现?
提前致谢。
【问题讨论】:
标签: iphone image navigation uinavigationbar
我正在 iphone 中开发一个应用程序。我必须在我的视图或 UINavigation 栏上添加图像。我的条件是图像将部分添加到导航栏,部分添加到视图中。
我已将它作为条形按钮项添加到标题视图中,但它的高度受条形高度的限制。我需要它放在导航栏下方。
如何实现?
提前致谢。
【问题讨论】:
标签: iphone image navigation uinavigationbar
您可以将图像视图添加为导航栏的子视图,如下所示:
[myNavBar insertSubview:myImageView atIndex:0];
【讨论】:
子类 UiNavigatonbar 类:)
【讨论】:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImageName"]];
imageView.frame = CGRectMake(100, 0, 200, 80);
[self.parentViewController.view.window addSubview:imageView];
[imageView release];
【讨论】:
#define kWidth [UIScreen mainScreen].bounds.size.width
In the <UIViewController.m>:
- (void)viewDidLoad
{
UIImageView *titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth-10, 0, 20, 20)];
titleImageView.image = [UIImage imageNamed:@"The Image Name"];
titleImageView.contentMode = UIViewContentModeScaleAspectFit;
self.navigationItem.titleView = titleImageView;
}
对我有用,对你有用吗?祝你好运!
【讨论】: