在我的应用程序委托 didFinishLaunchingWithOptions 函数中,我尝试自定义导航栏的外观。
[UINavigationBar appearance].translucent = NO;
[[UINavigationBar appearance]
setBackgroundImage:[UIImage
imageWithColor:[UIColor whiteColor]
size:CGSizeMake(1.0f, 1.0f)
]
forBarMetrics:UIBarMetricsDefault
];
[UINavigationBar appearance].shadowImage = [UIImage
imageWithColor:[UIColor redColor]
size:CGSizeMake(0.5f, 0.5f)
];
我希望看到一个高度为1像素、红色不透明的阴影,但实际上我得到了一个高度为2像素、红色半透明的阴影。我该如何让它完全按照我的要求显示?我已经按照UITabBar的类似外观设置进行了设置,但它表现得很奇怪。
动态创建图像的类别函数定义如下:
+ (UIImage*)imageWithColor:(UIColor *)color size:(CGSize)size
{
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
[UINavigationBar appearance].layer.borderWidth = 0.5f; [UINavigationBar appearance].layer.borderColor = [UIColor redColor].CGColor;
在导航栏下面没有显示任何内容。 - Pwner