我正在iphone中開發一個應用程序。我必須在我的視圖或UINavigation欄上添加圖像。我的情況是,圖像將被部分添加到導航欄上,並部分添加到視圖中。在UINavigationBar中添加UIImageView iphone
我已將它作爲barbutton項目添加到titleview中,但其高度受限於酒吧高度。我需要它降到導航欄下方。
它是如何實現的?
在此先感謝。
我正在iphone中開發一個應用程序。我必須在我的視圖或UINavigation欄上添加圖像。我的情況是,圖像將被部分添加到導航欄上,並部分添加到視圖中。在UINavigationBar中添加UIImageView iphone
我已將它作爲barbutton項目添加到titleview中,但其高度受限於酒吧高度。我需要它降到導航欄下方。
它是如何實現的?
在此先感謝。
您可以添加圖像視圖導航欄的子視圖,是這樣的:
[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;
}
它的工作對我來說,確實它適合你嗎?祝你好運!
-1這不起作用! –
...是的,它的確如此。嘗試一下。 – med200
對不起,我在insertSubview之前發佈了一個版本。編輯它,所以我可以給你一個投票 –