iOS7 UIImagePickerController cancel button disappe

2019-07-31 05:59发布

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

    }

enter image description here

3条回答
够拽才男人
2楼-- · 2019-07-31 06:14

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

Exampel on simulator (but it tested on )

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楼-- · 2019-07-31 06:33

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.

查看更多
小情绪 Triste *
4楼-- · 2019-07-31 06:39

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

enter image description here

查看更多
登录 后发表回答