change text color of UIBarButtonItem in UIImagePickerController? - ios

I use native UIImagePickerController in of my view controller.
I use a different color for UIBarButtonItem than what iPhone uses UIImagePickerController
is it possible for me to change textColor of UIImagePickerController.UIBarButtonItem ??
I tried
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.navigationItem.rightBarButtonItem.tintColor = [UIColor redColor];
for (UIBarButtonItem *item in picker.navigationItem.rightBarButtonItems) {
item.tintColor = [UIColor redColor];
}
for (UIView *view in picker.navigationBar.subviews) {
NSLog(#"%#", [[view class] description]);
if ([[[view class] description] isEqualToString:#"UIBarButtonItem"]) {
[(UIBarButtonItem *)view setTintColor:[UIColor redColor]];
}
}
[self presentViewController:picker animated:YES completion:NULL];
Output of NSlog was
_UINavigationBarBackground
_UINavigationBarBackIndicatorView
EDIT 2:
I needed to do
picker.navigationBar.tintColor = [UIColor redColor];

Related

How to remove UINavigationController / UINavigationBar background in objective-c?

I have 2 ViewController and first one is rootviewcontroller for NavigationController. I want to remove background of navigationbar in second viewcontroller and just show my navigationitem at top.
How to do that ? and what I should to do when I pop second viewcontroller, navigationbar have its old background not the secendview controller background ?
here is my code :
#implementation testView1
- (void)viewDidLoad
{
[super viewDidLoad];
[button addTarget:self action:#selector(ClickAction) forControlEvents:UIControlEventTouchUpInside ];
self.navigationController.navigationBar.translatesAutoresizingMaskIntoConstraints = false;
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationItem.title = #"Home";
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName:[UIColor whiteColor]};
}
-(void)ClickAction
{
testView2 *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"V2"];
[self.navigationController pushViewController:detail animated:YES];
}
#implementation testView2
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
self.title = #"No";
self.navigationController.navigationBar.barTintColor = nil;
self.navigationController.navigationBar.backgroundColor = nil;
self.navigationController.navigationBar.tintColor = nil;
self.navigationController.view.tintColor = nil;
self.navigationController.view.backgroundColor = nil;
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"left-arrow.png"] style:UIBarButtonItemStylePlain target:self action:#selector(Back:)];
backButtonItem.imageInsets = UIEdgeInsetsMake(45, 5, 45, 85);
self.navigationItem.leftBarButtonItem = backButtonItem;
}
-(void) Back:(id) sender
{
[self.navigationController popViewControllerAnimated:YES];
}
In firstcontroller
-(void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.translatesAutoresizingMaskIntoConstraints = false;
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationItem.title = #"Home";
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName:[UIColor whiteColor]};
[super viewWillAppear:animated];
}
and write code in SecondView controller
- (void)viewDidLoad
{
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
}
ViewController.h file:
- (void)showForViewController:(UIViewController*)controller;
ViewController.m file:
- (void)showForViewController:(UIViewController *)controller {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0"))
{
self.providesPresentationContextTransitionStyle = YES;
self.definesPresentationContext = YES;
[self setModalPresentationStyle:UIModalPresentationOverCurrentContext];
}
else
{
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext];
}
[controller.navigationController presentViewController:self animated:NO completion:nil];
}
I'm using this code for present ViewController with clear background (to see previous controller).

how to change color of status bar of imagepickercontroller ios?

I need something like this status bar image but i am getting the status hidden but still i can not change the color. I am getting this status bar withour color
This is what i am doing.
-
(void)showGallery
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = NO;
// picker.navigationBarHidden = YES;
// picker.toolbarHidden = YES;
picker.navigationController.navigationBar.barTintColor=[UIColor orangeColor];
picker.navigationBar.backgroundColor = [UIColor orangeColor];
picker.navigationBar.barStyle=UIBarStyleBlack;
[ picker.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor whiteColor]}];
[self presentViewController:picker animated:YES completion:NULL];
}
Use three steps:
1: Add UINavigationControllerDelegate, UIImagePickerControllerDelegate to your #interface yourController ()<>
2:
imagePickerController.delegate = self;
3:
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Try This:-
1.Create a view with height 20 points and change the background color to attach the viewcontrollerView (OR) change the background colour of your view controller follow like
UIView*statusbarview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
statusbarview.backgroundColor = [UIColor greenColor];
[self.view addSubview:statusbarview];
(OR)
self.view.backgroundColor = [UIColor redColor];
This solved my problem.
-(void)showGallery
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = NO;
picker.modalPresentationStyle = UIModalPresentationFullScreen;
picker.navigationBar.translucent = NO;
picker.navigationBar.barTintColor = [UIColor orangeColor];
picker.navigationBar.tintColor = [UIColor whiteColor];
picker.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName: [UIColor whiteColor]};
[self presentViewController:picker animated:YES completion:nil];
}

How to create GalleryShortcut when presenting UIImagePickerController

I want to give option for user to take a photo or upload one as his avatar in my app.
I believe there is no need to put two different buttons for that, so instead I would like to make the next scenario:
user clicks on "Add Picture" button and automatically UIImagePicker with source control - camera is presented.
But, I want to have shortcut for gallery in the corner, where user could click, get into gallery and search for pic he would use.
Here is the screenshot of what I need:
Part with red circle is important part.
How do I put it there?
(Initially it's not there)
There is no pre-build way to do this.
What you can do is to make an overlay for Camera View.
Bear in mind that you have to make different view for each device, as every device already has different positioning inside the CameraView.
One example would be this:
- (IBAction)addImage:(UIButton *)sender {
UIView* overlay = [[UIView alloc] initWithFrame:CGRectMake(20,self.view.frame.size.height-60 , 40, 40)];
overlay.opaque=NO;
overlay.backgroundColor = [UIColor clearColor];
UIButton* btnGallery = [[UIButton alloc]initWithFrame:CGRectMake(0,0 , 40, 40)];
[btnGallery setImage:[UIImage imageNamed:#"image_gallery"] forState:UIControlStateNormal];
btnGallery.backgroundColor = [UIColor whiteColor];
[overlay addSubview:btnGallery];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = YES;
[imagePicker.view addSubview:overlay];
[btnGallery addTarget:self
action:#selector(openGallery)
forControlEvents:UIControlEventTouchUpInside];
_picker = imagePicker;
[self presentViewController:imagePicker
animated:YES
completion:nil];
}
-(void)openGallery
{
UIImagePickerController *gallery = [[UIImagePickerController alloc] init];
gallery.delegate = self;
gallery.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
gallery.mediaTypes = #[(NSString *) kUTTypeImage];
gallery.allowsEditing = YES;
_gallery = gallery;
[_picker presentViewController:gallery
animated:YES
completion:nil];
}

How to add the UIImagePickerController in the custom view?

How to add the UIImagePickerController in the view ? If I add the image picker to the view, its show on the full screen. I need to show the on the centre of the view, But UIImagePickerController hide the navigation bar.
How add the UIImagePickerController in the view and also show the navigation bar ?
I am using the following code, I got the output like this(screenshot).
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
imagePicker.showsCameraControls = NO;
imagePicker.navigationBarHidden = NO;
imagePicker.toolbarHidden = YES;
imagePicker.wantsFullScreenLayout = NO;
imagePicker.delegate = self;
imagePicker.cameraOverlayView = cameraOverlayView;
[self presentViewController:imagePicker animated:NO completion:nil];
I need some for show the navigation bar while add the UIImagePickerController in the view. Thanks in advance.
If you are develop application for iPad then you can use popoverviewcontroller to show imagepickerviewcontroller with navigation bar
please see thie link :
How to use UIImagePickerController in iPad?
Correct way to customize media capture here using Assets Library.
Simple way (in some cases) is using overlay view with frame size of whole screen and add controls on that view which simulate navigation bar.
if (_pickerOverlay == nil) {
_pickerOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
//red transparent tint for demo
_pickerOverlay.backgroundColor = [UIColor colorWithRed:1.0
green:0.0
blue:0.0 alpha:0.6];
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeSystem];
btnBack.frame = CGRectMake(20, 20, 250, 40);
[btnBack setTitle:#"Custom buttom" forState:UIControlStateNormal];
btnBack.backgroundColor = [UIColor whiteColor];
[_pickerOverlay addSubview:btnBack];
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.cameraOverlayView = _pickerOverlay;
[self presentViewController:picker animated:YES completion:nil];

easier way to subview a UIImagePickerController? mines not working

When I run my code and launch the camera with the code below I get my custom overlayView along with the default camera buttons. The only problem is, now, I get a blank black box where my UIImagePicker once was. I am simply trying to create a camera using the default UIImagePicker controls and buttons and then add my own IBOutlet UILabel over top of the default imagePickerController so that my label is displayed along with all the default camera controls. I'm having a terrible time accomplishing this though. cheers!
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.videoMaximumDuration = 10;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = self.imagePicker.cameraOverlayView.frame;
self.imagePicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
}
[self presentViewController:self.imagePicker animated:YES completion:nil];
}
Try to use my code. It worked fine. May be you achieve what you want. I created a controller, and used it's view to set cameraOverlayView property. I didn't use nib files, I created everything programmatically.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.tabBarItem.image = [UIImage imageNamed:#"86-camera"];
self.cameraOverlayViewController = [[CameraOverlayViewController alloc] init];
self.cameraOverlayViewController.picker = picker;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.toolbarHidden = YES;
picker.cameraOverlayView = self.cameraOverlayViewController.view;
picker.delegate = self.cameraOverlayViewController;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
This is a code for custom CameraOverlayViewController:
Interface file:
#import <UIKit/UIKit.h>
#interface CameraOverlayViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (nonatomic, strong) UIImagePickerController *picker;
#end
Implementation file:
#import "CameraOverlayViewController.h"
#import "BButton.h"
#import "AnalyseViewController.h"
#import "Tree.h"
#interface CameraOverlayViewController ()
{
}
#end
#implementation CameraOverlayViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.view.backgroundColor = [UIColor clearColor];
self.view.opaque = NO;
}
return self;
}
- (void)loadView
{
[super loadView];
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bottom - 150, 320, 150)];
bottomView.backgroundColor = [UIColor blackColor];
BButton *button = [[BButton alloc] initWithFrame:CGRectMake(50, 25, 220, 50) type:BButtonTypePrimary];
[button setTitle:#"Сфотографировать" forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[bottomView addSubview:button];
[self.view addSubview:bottomView];
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
topView.backgroundColor = [UIColor clearColor];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 310, 60)];
infoLabel.backgroundColor = [UIColor clearColor];
infoLabel.font = [UIFont fontWithName:#"Georgia" size:18];
infoLabel.textColor = [UIColor whiteColor];
infoLabel.textAlignment = NSTextAlignmentCenter;
infoLabel.numberOfLines = 0;
infoLabel.text = #"Поместите лист дерева внутри рамки, чтобы\nсфотографировать его.";
[topView addSubview:infoLabel];
[self.view addSubview:topView];
UIView *bordersView = [[UIView alloc] initWithFrame:CGRectMake(10, topView.bottom + 10, 300, 300)];
bordersView.layer.cornerRadius = 10;
bordersView.layer.borderColor = [UIColor whiteColor].CGColor;
bordersView.layer.borderWidth = 2;
bordersView.backgroundColor = [UIColor clearColor];
[self.view addSubview:bordersView];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
AnalyseViewController *analyseViewController = [[AnalyseViewController alloc] initWithNibName:nil bundle:nil];
analyseViewController.baseImage = image;
analyseViewController.treesArray = [Tree retrieveAllTrees];
UINavigationController *analyseNavController = [[UINavigationController alloc] initWithRootViewController:analyseViewController];
[AppDel.tabBarController presentViewController:analyseNavController animated:YES completion:nil];
}
#pragma mark - Other methods
- (void)buttonClicked:(id)sender
{
[self.picker takePicture];
}
#end
Delete unneeded classes like BButton yourself.
fixed it with this. I did some research on CGPoints & CGRect and come up with this solution. Not sure if it is the most elegant solution but it works and seems to make pretty good sense. - (void)viewDidLoad
{
[super viewDidLoad];
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = YES;
self.imagePicker.videoMaximumDuration = 10;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = CGRectMake(160,0,0,0);
self.imagePicker.cameraOverlayView = self.overlayView;
}

Resources