我可以自定義QlPreviewController控制器中導航欄的顏色嗎?如何自定義qlpreviewcontroller中導航欄的顏色
我曾嘗試以下
[[UINavigationBar appearanceWhenContainedIn: [QLPreviewController class], nil] setBarTintColor: [UIColor redColor]];
,但它不工作。
謝謝。
我可以自定義QlPreviewController控制器中導航欄的顏色嗎?如何自定義qlpreviewcontroller中導航欄的顏色
我曾嘗試以下
[[UINavigationBar appearanceWhenContainedIn: [QLPreviewController class], nil] setBarTintColor: [UIColor redColor]];
,但它不工作。
謝謝。
請應用委託使用以下代碼
[[UINavigationBar的外觀] setBarTintColor:#your顏色#]。
*在AppDelegate.m –
是啊,有一個與barTintColor上QLPreviewController爲iOS 一個錯誤,如果你是顯示它通過presentViewController: animated:
這裏是我的解決方案,使用了setBackgroundImage:使用1x1圖片代替setBarTintColor:
[[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[QLPreviewController class]]]
setBackgroundImage:[UIImage imageWithColor:[UIColor redColor]]
forBarMetrics:UIBarMetricsDefault];
和imageWithColor:是我的自定義類別的UIImage中的方法,它返回可調整大小的1x1圖像所期望的顏色(紅色在上面的例子中)的:
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
const CGFloat alpha = CGColorGetAlpha(color.CGColor);
const BOOL opaque = alpha == 1;
UIGraphicsBeginImageContextWithOptions(rect.size, opaque, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
我也建議用來包裝這一IOS版本檢查等:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11.0")) {
[[UINavigationBar appearance...
setBackgroundImage:[UIImage imageWithColor:...]
forBarMetrics:UIBarMetricsDefault];
}
哪裏SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO
距離:
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
不錯的建議,通過設置圖像爲我工作。 – johnrechd
請不要標記如下所示的代碼:\'code \',而是在代碼前添加四個空格。也請解釋什麼是'不工作'。運行此類代碼時,您的系統是否會爆炸? – SteveFest