為相機制作閃光燈,在導航欄自定義了“閃光”圖案,希望點擊時變換圖片,但是一直沒有改變,原來是因為設置了Global Tint的顏色,所以系統會自動把圖片的顏色改為Global Tint的顏色。
解決方案,設置圖片時,添加:imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
源碼:
- (void) setFlashOn:(BOOL)isOn
{
if (self.captureDevice.hasFlash) {
UIImage* flashlIcon;
[self.captureDevice lockForConfiguration:nil]; //you must lock before setting torch mode
if (isOn) {
NSLog(@"set flash on");
[self.captureDevice setFlashMode:AVCaptureFlashModeOn];
flashlIcon = [UIImage imageNamed:@"flash_on"];
}
else{
NSLog(@"set flash off");
[self.captureDevice setFlashMode:AVCaptureFlashModeOff];
flashlIcon = [UIImage imageNamed:@"flash_off"];
}
[self.captureDevice unlockForConfiguration];
[self.navigationItem.rightBarButtonItem setImage:[flashlIcon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
}
else{
NSLog(@"Sorry, this device doesn't have flash.");
}
}http://stackoverflow.com/questions/21252194/navigation-bar-button-item-image-color-is-different-when-design-through-xib-of-x