Trong chức năng didFinishLaunchingWithOptions của đại biểu ứng dụng của tôi, tôi cố gắng tùy chỉnh giao diện của thanh điều hướng của tôi.Làm cách nào để đặt hình ảnh có độ bóng cao 1px mờ cho UINavigationBar?
[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)
];
Tôi mong đợi một bóng đỏ đục 1px cao. Thay vào đó, tôi được cho một cái bóng màu đỏ mờ 2px. Làm thế nào có thể làm cho nó xuất hiện chính xác như tôi muốn nó? Tôi đã thực hiện các thiết lập ngoại hình tương tự cho UITabBar. Mặt khác, nó hoạt động rất tốt.
Chức năng loại đó tạo ra hình ảnh động được định nghĩa như vậy:
+ (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;
}
có bạn nhìn vào chỉ thêm một cái bóng đến CALayer? xem http://stackoverflow.com/questions/805872/how-do-i-draw-a-shadow-under-a-uiview – cmyr
@cmyr '[UINavigationBar xuất hiện] .layer.borderWidth = 0.5f; [UINavigationBar xuất hiện] .layer.borderColor = [UIColor redColor] .CGColor; 'không hiển thị gì bên dưới thanh điều hướng. – Pwner
bạn đã đặt clipToBounds của lớp thành KHÔNG? – cmyr