los*_*sit 7 iphone uinavigationbar
我正在为我的UINavigationBar添加自定义背景.只要手机处于纵向模式,它就能正常工作.一旦我切换到横向模式,一半的条形显示为蓝色(默认的导航栏颜色),其中一半有我的图像
如何在横向模式下拉伸图像并在纵向模式下再次缩小图像?
谢谢
解决方案如果
有人正在寻找如何将图像添加到导航栏的答案 - 就在这里
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480.0, 44.0)];
[imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"navbar_landscape" ofType:@"png"]]];
[navigationController.navigationBar addSubview:imgView];
[imgView release];
Run Code Online (Sandbox Code Playgroud)
在两种屏幕方向模式下,使用起来都要好得多
[navigationController.navigationBar insertSubview:imgView atIndex:0];
Run Code Online (Sandbox Code Playgroud)
这会将图像视图放在所有其他视图下,并且所有默认导航栏元素(标题,标准按钮)都可以正常工作.
小智 6
经过一些研究和追踪和错误,我找到了一个解决方法,当你进入电影播放模式时,它不会取代导航栏.希望这不会导致应用程序批准出现问题,但基于这篇文章,我认为应该没问题:
http://developer.apple.com/iphone/library/qa/qa2009/qa1637.html
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
if([self isMemberOfClass: [UINavigationBar class]]){
UIImage *image = [UIImage imageNamed:@"navBarBackground.png"];
CGContextClip(ctx);
CGContextTranslateCTM(ctx, 0, image.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextDrawImage(ctx, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), image.CGImage);
}else{
[super drawLayer:layer inContext:ctx];
}
}
@end
Run Code Online (Sandbox Code Playgroud)
您可能需要设置背景图像视图的 autoresizingMask ;尝试使用UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
| 归档时间: |
|
| 查看次数: |
8857 次 |
| 最近记录: |