Ios 在UIImagePickerController中,是否未显示取消按钮?
这里我使用下面的代码。如果有人知道这个问题,请帮助我。 我也尝试了下面的URL,但它不起作用。请帮帮我 我的问题: 我的要求:Ios 在UIImagePickerController中,是否未显示取消按钮?,ios,objective-c,ios7,uiimagepickercontroller,Ios,Objective C,Ios7,Uiimagepickercontroller,这里我使用下面的代码。如果有人知道这个问题,请帮助我。 我也尝试了下面的URL,但它不起作用。请帮帮我 我的问题: 我的要求: 更改UIImagePickerController navigationBar.tintColor 请尝试以下代码: UINavigationBar *bar = [self.navigationController navigationBar]; [bar setTintColor:[UIColor blueColor]]; 请尝试以下代码: UIIm
更改UIImagePickerController navigationBar.tintColor 请尝试以下代码:
UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor blueColor]];
请尝试以下代码:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];
并添加委托方法:-(void)imagePickerController:(UIImagePickerController*)PickerDidFinishPickingMediaWithInfo:(NSDictionary*)info
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:^{
}];
self.img = image;
[self.iconBtn setBackgroundImage:image forState:UIControlStateNormal];
}
我认为您尚未将viewController嵌入导航控制器 请这样做,然后尝试代码:(Objective-c)
我使用的代码与你发布的代码相同。它显示“取消”按钮 可能您正在使用任何自定义导航栏,并且您将app delegate的属性设置为更改导航栏的色调
看起来苹果在这方面犯了一些错误(iOS 10,Xcode 8),因为在控制器没有
topItem
属性或navigationController
属性之前,仅仅更改UIImagePickerController的色调是不可能的。因此,我们在UIImagePickerController扩展中进行了更改。但是我在那些重写的方法中选中了navigationController
和topItem
:viewDidLoad
,ViewWillAsped
,ViewDidAsped
。但它仍然是零。所以我决定把它签入视图willlayoutsubviews
,瞧!它不是零,所以我们可以在这里设置完全正确的bar-tint颜色
下面是一个例子:
extension UIImagePickerController {
open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.black
self.navigationBar.topItem?.rightBarButtonItem?.isEnabled = true
}
}
不要忘记调用super.viewWillLayoutSubviews,这非常重要;-)
编辑:但在返回相册屏幕时仍然存在问题。这就是我的工作原理:
present(imagePicker, animated: true, completion: {
imagePicker.navigationBar.topItem?.rightBarButtonItem?.tintColor = .black
})
let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: .blue), NSFontAttributeName: UIFont.boldSystemFont(ofSize: 16.0)], for: .normal)
如果所有的努力都没有奏效,那么您必须使用appearance()方法。因此,请尝试在要显示的任何视图控制器(UIImagePickerController)中写入以下行。您可以在任何类中使用外观,但可能出于其他目的使用了UIBarButtonItem.appearance(),因此请找到它并在ViewDidEnglishe()中编写该代码
似乎更新某些项目属性会使按钮可见,所以。。。只需像这样启用它:
present(imagePicker, animated: true, completion: {
self.imagePicker.navigationBar.topItem?.rightBarButtonItem?.isEnabled = true
})
如果上述任何一项都不适用于您,
在定义UIImagePickerController
imagePicker.modalPresentationStyle = .popover // Or.fullScreen (Can also check cases for iPad and iPhone as per requirement)
对我来说就像一个符咒。被这件事搞得一团糟这对我来说很有效:
present(imagePicker, animated: true, completion: {
imagePicker.navigationBar.topItem?.rightBarButtonItem?.tintColor = .black
})
let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: .blue), NSFontAttributeName: UIFont.boldSystemFont(ofSize: 16.0)], for: .normal)
我想这会对您有所帮助。只需将代码粘贴到ImagePickerController IDCancel中,然后将其删除(Swift 4)
Swift 4.2解决方案,将以下代码添加到AppDelegate的didFinishLaunchingWithOptions中
我也面临着同样的问题,在浪费了很多时间之后,我找到了解决办法。我自定义了导航栏的外观,如下面的代码,这就是为什么会发生这个问题
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "ic_left")
let attributes = [NSAttributedString.Key.font: UIFont(name: "FuturaPT-Medium", size: 16)!]
UINavigationBar.appearance().titleTextAttributes = attributes
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "line.png"),for: .bottom,barMetrics: .default)
UINavigationBar.appearance().shadowImage = UIImage(named: "line.png")
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor:
UIColor.clear],用于:。正常)
这只是导航栏的自定义外观,我们只需要更改最后一行代码,因为我已将标题颜色设置为“清除”。这真的很简单。在显示图像选择器控制器之前,请输入此代码
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor:
UIColor.black],用于:。正常)
如果您不希望导航栏按钮标题使文本颜色变为清晰,请再次单击。
谢谢请在swift 3或更高版本中尝试此代码
let picker = UIImagePickerController()
picker.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.white
子类UIPickerViewController如下所示:
class CustomImagePicker: UIImagePickerController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UINavigationBar.appearance().tintColor = UIColor.black
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.init(red: 0.0, green: 122.0/255.0, blue: 1.0, alpha: 1.0)], for: .normal)
}
override func viewWillDisappear(_ animated: Bool) {
UINavigationBar.appearance().tintColor = UIColor.white // your color
UIBarButtonItem.appearance().setTitleTextAttributes(nil, for: .normal)
super.viewWillDisappear(animated)
}
}
并用作:
func openGallary()
{
picker!.sourceType = UIImagePickerController.SourceType.photoLibrary
picker!.modalPresentationStyle = .currentContext
self.present(picker!, animated: true, completion: nil)
}
我也做了同样的过程,你可以从gallery@中选择任何图像,当时这种方法称为didFinishPickingMediaWithInfo,但我的问题是在选择图像之前“取消按钮”不显示你是否在应用程序中使用外观类别UINavigationBar
?还是其他?@Venkatesh:请检查用户提供的答案,并投票选出最佳答案。如果您的问题通过使用答案得到解决,您是否找到了解决方案请参考此答案如果每种情况都不起作用,请从故事板将视图控制器嵌入导航控制器这有助于我获得取消按钮。但现在在相机里找不到滚动条上的按钮项目。如果你找到解决方法,请指导我。谢谢。谢谢,将modalPresentationStyle设置为.fullscreen对我有用。如果可用(iOS 11.0,*){UINavigationBar.appearance(当包含实例of:[UIDocumentBrowserveWController.self])。tintColor=nil UINavigationBar.appearance(当包含实例of:[UIImagePickerController.self]).tintColor=nil}请尝试在应用程序委托中添加此项。我觉得它真的很有用。我想在这之后你就不需要上面的了。如果有帮助,请告诉我
UINavigationBar.appearance(whenContainedInInstancesOf: [UIImagePickerController.self]).tintColor = .black
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "ic_left")
let attributes = [NSAttributedString.Key.font: UIFont(name: "FuturaPT-Medium", size: 16)!]
UINavigationBar.appearance().titleTextAttributes = attributes
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "line.png"),for: .bottom,barMetrics: .default)
UINavigationBar.appearance().shadowImage = UIImage(named: "line.png")
let picker = UIImagePickerController()
picker.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.white
class CustomImagePicker: UIImagePickerController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UINavigationBar.appearance().tintColor = UIColor.black
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.init(red: 0.0, green: 122.0/255.0, blue: 1.0, alpha: 1.0)], for: .normal)
}
override func viewWillDisappear(_ animated: Bool) {
UINavigationBar.appearance().tintColor = UIColor.white // your color
UIBarButtonItem.appearance().setTitleTextAttributes(nil, for: .normal)
super.viewWillDisappear(animated)
}
}
func openGallary()
{
picker!.sourceType = UIImagePickerController.SourceType.photoLibrary
picker!.modalPresentationStyle = .currentContext
self.present(picker!, animated: true, completion: nil)
}