2013-09-22 57 views
1

取消按鈕是錯過?!我怎樣才能解決這個問題?非常感謝你。iOS7 UIImagePickerController取消按鈕消失

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) 
    { 
     if(buttonIndex == 1) 
     { 
      self.ctr = [[UIImagePickerController alloc] init]; 
      self.ctr.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
      self.ctr.delegate = self; 
      self.ctr.allowsEditing = YES; 
      [self presentModalViewController:self.ctr animated:YES]; 
     } 

    } 

enter image description here

+0

嘗試子類UIImagePickerController然後在你的子類 - (void)viewDidLoad中,添加一個取消按鈕。 –

+1

@Basheer_CAD謝謝。 – jxdwinter

+0

您是否找到解決方案?我也有同樣的問題,並嘗試了很多方法。但是,它不能被顯示。 – mmjuns

回答

2

只要改變的UIImagePickerController navigationBar.tintColor,應該沒問題。

self.ctr.navigationBar.tintColor = [UIColor redColor];//Cancel button text color 
[self.ctr.navigationBar setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor blackColor]}];// title color 

enter image description here

+0

嘿@jxdwinter具有相同的問題,但對於UIImagePickerControllerSourceTypeCamera。我已經添加了你的代碼,但沒用。請幫幫我。 – Trup

0

看起來像蘋果做了一些錯誤,它(的iOS 10,Xcode中8),因爲的UIImagePickerController的只是改變色調的顏色無法完成的工作,事業,之前控制器沒有topItem財產,或navigationController財產。所以已經做了UIImagePickerController extension的更改。但我在那些被忽略的方法中檢查了navigationControllertopItemviewDidLoad,viewWillAppear,viewDidAppear。但它仍然是nil。所以我決定檢查它在viewWillLayoutSubviews,瞧!這不是零,所以我們可以在這裏設置精確的rightBarButtomItem的色調顏色!

這裏是例子:

extension UIImagePickerController { 
     open override func viewWillLayoutSubviews() { 
      super.viewWillLayoutSubviews() 
      self.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.black 
      self.navigationBar.topItem?.rightBarButtonItem?.isEnabled = true 
     } 
    } 

Exampel on simulator (but it tested on)

而且不要忘記調用super.viewWillLayoutSubviews,這是非常重要的;-) 編輯:但它仍然有問題,當返回到專輯畫面。