iOS7 UIImagePickerController cancel button disappear

夙愿已清 提交于 2019-12-11 13:12:57

问题


The Cancel button is miss?! How can I fix this? Thank you very much.

    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];
        }

    }


回答1:


Just change the UIImagePickerController navigationBar.tintColor, it should be OK.

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




回答2:


Looks like apple made some mistake with it (iOS 10, Xcode 8) because just changing tint color of UIImagePickerController could not be done, cause, before controller isn't have topItem property, or navigationController property. So have done the changes in UIImagePickerController extension. But I checked navigationController and topItem in those overrided methods: viewDidLoad, viewWillAppear, viewDidAppear. but it still was nil. So i decide to check it in viewWillLayoutSubviews, and voila! It's wasn't nil, so we can set bar tint color of exact rightBarButtomItem here!

Here is example:

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

And don't forget to call super.viewWillLayoutSubviews, it's very important ;-) EDIT: But it still has problems when return to the albums screen..




回答3:


Change the tintColor

self.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.black 

If that doesn't work run through your view controllers to see if there isn't a place where you changed the appearance of the navigation bar and reset the change.



来源:https://stackoverflow.com/questions/18941582/ios7-uiimagepickercontroller-cancel-button-disappear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!