2015-02-10 75 views
1

這裏我使用下面的代碼。如果有人知道這個問題,請幫助我。 ,我也試過下面的網址,但它不工作。請幫我在UIImagePickerController取消按鈕不顯示?

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

我的問題: enter image description here

我的所需物品: enter image description here

+0

你使用'appearance'類別'UINavigationBar'在你的應用程序?還是其他? – orkenstein 2015-02-10 11:47:29

+0

@Venkatesh:請檢查用戶提供的答案並投票選出最佳答案。也接受一些人的答案,如果你的問題得到解決通過使用的答案 – 2017-10-13 07:18:46

+0

你設法找到這個解決方案 – 2018-02-19 07:21:16

回答

0

變化的UIImagePickerController navigationBar.tintColor 試試這個代碼:

UINavigationBar *bar = [self.navigationController navigationBar]; 
    [bar setTintColor:[UIColor blueColor]]; 
+0

我也試過這個代碼,但它不工作 – 2015-02-10 11:04:41

+0

檢查我的編輯答案@VenkateshG – 2015-02-10 11:07:17

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

我也做了同樣的過程,文從圖庫中選擇任何圖像@當時這種方法稱爲didFinishPickingMediaWithInfo,但我的概率是在選擇圖像之前「取消按鈕」不顯示 – 2015-02-10 11:22:56

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

我想你還沒有嵌入的viewController到導航控制器

請做到這一點並嘗試下面的代碼:(Objectiv e - 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; 
} 
+0

從視頻控制器嵌入您的視圖控制器到導航控制器 – 2015-04-07 09:31:38

0

我使用了與您發佈的代碼相同的代碼。它顯示「取消」按鈕。

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

可能是您正在使用任何自定義導航欄,並將應用程序委託的屬性設置爲更改導航欄的色調顏色。

enter image description here

1

看起來像蘋果做了一些錯誤,它(的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,這是非常重要的;-) 編輯:但它仍然有問題,當返回到專輯畫面。 。

+0

這幫助我獲得取消按鈕。但現在在相機卷中無法找到條形按鈕項目。請指導我如果你找到解決方法。謝謝。 – 2017-04-12 06:57:46

2

這是對我工作:

present(imagePicker, animated: true, completion: { 
     imagePicker.navigationBar.topItem?.rightBarButtonItem?.tintColor = .black 
    }) 
+0

不適合我的目的。 – neha 2018-01-23 12:36:37

相關問題