2013-09-22 123 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,这是非常重要的;-) 编辑:但它仍然有问题,当返回到专辑画面。