这里我使用下面的代码。如果有人知道这个问题,请帮助我。 我也试过下面的网址,但它不起作用。请帮帮我
iOS7 UIImagePickerController cancel button disappear UIImagePickerController inside UIPopoverController doesn't show Cancel button on iOS7
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
picker.navigationBar.tintColor = [UIColor redColor];
picker.navigationBar.barStyle = UIBarStyleBlackOpaque;
picker.navigationBar.topItem.rightBarButtonItem.tintColor = [UIColor blackColor];
我的问题:
我的需求:
答案 0 :(得分:7)
这对我有用:
present(imagePicker, animated: true, completion: {
imagePicker.navigationBar.topItem?.rightBarButtonItem?.tintColor = .black
})
答案 1 :(得分:2)
如果每次努力都不起作用,那么你必须使用appearance()方法。因此,尝试在要呈现的任何视图控制器(UIImagePickerController)中编写以下行。您可以在任何类中使用外观,但您可能已将UIBarButtonItem.appearance()用于其他目的,因此请在viewDidDisappear()中找到并编写该代码。
var gm = require('../')
, dir = __dirname + '/imgs'
gm(dir + "/original.jpg")
.crop(140,100)
.background("#FF0000")
.extent(340,300)
.write(dir + '/background.jpg', function (err) {
if (err) return console.dir(arguments)
console.log(this.outname + " created :: " + arguments[3])
});
答案 2 :(得分:1)
我认为你没有将viewController嵌入到导航控制器
请这样做并尝试代码:(目标 - c)
-(void)viewDidLoad
{
[super viewDidLoad];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:^{
}];
UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 300)];
imageview.image=image;
}
答案 3 :(得分:1)
我使用了您发布的相同代码。它显示“取消”按钮。
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
picker.navigationBar.tintColor = [UIColor redColor];
picker.navigationBar.barStyle = UIBarStyleBlackOpaque;
picker.navigationBar.topItem.rightBarButtonItem.tintColor = [UIColor blackColor];
[self presentViewController:picker animated:YES completion:NULL];
可能您正在使用任何自定义导航栏,并且您将app delegate的属性设置为更改导航文件的色调。
答案 4 :(得分:1)
好像更新某些项目属性可以使按钮可见,所以...只需将其启用即可:
present(imagePicker, animated: true, completion: {
self.imagePicker.navigationBar.topItem?.rightBarButtonItem?.isEnabled = true
})
答案 5 :(得分:1)
如果以上任何一项都不适合您,
定义UIImagePickerController
imagePicker.modalPresentationStyle = .popover // Or.fullScreen (Can also check cases for iPad and iPhone as per requirement)
像魅力一样为我工作。被这个烦恼了
答案 6 :(得分:1)
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)
}
}
并使用As:
func openGallary()
{
picker!.sourceType = UIImagePickerController.SourceType.photoLibrary
picker!.modalPresentationStyle = .currentContext
self.present(picker!, animated: true, completion: nil)
}
答案 7 :(得分:0)
更改UIImagePickerController navigationBar.tintColor 试试这段代码:
UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor blueColor]];
答案 8 :(得分:0)
UIImagePickerController *imgPicker=[[UIImagePickerController alloc]init];
imgPicker.delegate = self;
imgPicker.navigationBar.barStyle = UIBarStyleBlackOpaque;
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imgPicker.allowsEditing = NO;
if([UIImagePickerController isSourceTypeAvailable: sourceType])
{
imgPicker.sourceType=sourceType;
[self presentViewController:imgPicker animated:YES completion:NULL];
}
答案 9 :(得分:0)
这对我有用:
let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: .blue), NSFontAttributeName: UIFont.boldSystemFont(ofSize: 16.0)], for: .normal)
答案 10 :(得分:0)
Swift 4.2解决方案,将以下代码添加到AppDelegate的didFinishLaunchingWithOptions
UINavigationBar.appearance(whenContainedInInstancesOf: [UIImagePickerController.self]).tintColor = .black
答案 11 :(得分:0)
我也遇到过同样的问题,在浪费大量时间后,我找到了解决方案。我已自定义导航栏外观(如以下代码所示),以说明发生此问题的原因。
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],用于:.normal)
这只是导航栏的自定义外观,我们只需要更改最后一行代码,因为我将标题颜色设置为清除。这真的很简单。在展示您的图像选择器控制器之前,请放置此代码。
UIBarButtonItem.appearance()。setTitleTextAttributes([[NSAttributedString.Key.foregroundColor: UIColor.black],用于:.normal)
再次,如果您不想导航栏按钮标题,请清除文本颜色。 谢谢
答案 12 :(得分:0)
请尝试使用此代码,以获取3或更高版本
let picker = UIImagePickerController()
picker.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.white
答案 13 :(得分:-1)
试用此代码:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];
并添加委托方法:- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(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];
}
答案 14 :(得分:-1)
我认为这将对您有所帮助。只需将代码粘贴到imagePickerControllerDidCancel中,然后将其关闭(快速键4)。
picker.setNavigationBarHidden(false, animated: true)