iOS: [imagePickerController.cameraOverlayView addSubview:] not working - iphone

I am attempting to add a UIToolbar to my cameraOverlayView for a custom imagePickerController. This is the code I want to use:
[self.imagePickerController.cameraOverlayView addSubview:self.topToolbar];
When trying to add a UIToolbar, nothing shows up. Encapsulating it into a UIView and setting it to the view property works if I use:
[self.imagePickerController.cameraOverlayView addSubview:self.view];
But this limits me to using one view for my overlay when I want to add several. I understand I can encapsulate everything into one big view, however when I do that, my bottom toolbar does not appear properly.
Has anyone had success in adding a UIToolbar as a subview to a cameraOverlayView?

i think you need a view to put all the things you need in your cameraOverlay.
for example:
TempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
TempView.alpha = 1.0;
anImageView1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#""]];
anImageView1.frame = CGRectMake(0, 0, anImageView1.image.size.width, anImageView1.image.size.height-50);
anImageView1.hidden = NO;
anImageView1.alpha = 1.0f;
tabBarHolder = [[UIImageView alloc]init];
tabBarHolder.backgroundColor = [UIColor blackColor];
tabBarHolder.frame = CGRectMake(0, 415, 320, 80);
tampBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 430, 35, 35)];
[tampBtn setBackgroundImage:[UIImage imageNamed:#"iconBack.png"] forState:UIControlStateNormal];
[tampBtn addTarget:self
action:#selector(xup)
forControlEvents:UIControlEventTouchUpInside];
ctampBtn = [[UIButton alloc] initWithFrame:CGRectMake(145, 430, 35, 35)];
[ctampBtn setBackgroundImage:[UIImage imageNamed:#"iconCamera.png"] forState:UIControlStateNormal];
[ctampBtn addTarget:self
action:#selector(takephoto)
forControlEvents:UIControlEventTouchUpInside];
[TempView addSubview:ctampBtn];
[TempView addSubview:tampBtn];
[TempView addSubview:anImageView1];
[TempView addSubview:tabBarHolder];
[TempView bringSubviewToFront:tabBarHolder];
[TempView bringSubviewToFront: ctampBtn];
[TempView bringSubviewToFront:tampBtn];
imagePicker.cameraOverlayView =TempView;

Related

How to add two buttons to the UINavigation bar title view

can any body help me how to add two buttons to the navigation title view by using the title view property. I tried but, able to add only one button by using the following code.
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
customView.backgroundColor = [UIColor redColor];
UIButton *b1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
UIButton *b2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[b1 setTitle:#"Hai" forState:UIControlStateNormal];
[b2 setTitle:#"Hello" forState:UIControlStateNormal];
[customView insertSubview:b1 atIndex:0];
[customView insertSubview:b2 atIndex:1];
self.navigationItem.titleView = customView;
use this code:
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
customView.backgroundColor = [UIColor redColor];
UIButton *b1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
UIButton *b2 = [[UIButton alloc] initWithFrame:CGRectMake(50, 0, 50, 50)];
[b1 setTitle:#"Hai" forState:UIControlStateNormal];
[b2 setTitle:#"Hello" forState:UIControlStateNormal];
[customView insertSubview:b1 atIndex:0];
[customView insertSubview:b2 atIndex:1];
self.navigationItem.titleView = customView;
Outputs:
It's because you have added the same frame for both Buttons. So, the Buttons are actually overlapped. You should use this code instead :
UIButton *b1=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
UIButton *b2=[[UIButton alloc]initWithFrame:CGRectMake(60, 0, 50, 50)];
Then you can simply add these buttons to your custom view.
[cusotmView addSubView:b1];
[cusotmView addSubView:b2];
Reason for Error :
You can't directly add UIButtons. You need to wrap them as UIBarButtonItems first.
Sample Code :
UIBarButtonItem *btn1 = [[UIBarButtonItem alloc] initWithCustomView:b1];
UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithCustomView:b2];
[cusotmView addSubView:btn1];
[cusotmView addSubView:btn2];

Back button on custom navigation bar

I am trying to develop an app with a navigation bar of custom size. (100px) In the navigation bar, I also want to include a back button. I have added both of them using the child view, but the back button is not working:
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backBtnImage = [UIImage imageNamed:#"menueButton.png"];
UIImage *backBtnImagePressed = [UIImage imageNamed:#"menueButton.png"];
backBtn.exclusiveTouch = YES;
[backBtn addTarget:self action:#selector(back:) forControlEvents:UIControlEventTouchUpInside];
[backBtn setBackgroundImage:backBtnImage forState:UIControlStateNormal];
[backBtn setBackgroundImage:backBtnImagePressed forState:UIControlStateHighlighted];
backBtn.frame = CGRectMake(0, -40, 35, 32);
UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, -40, 35 , 32)];
[backButtonView addSubview:backBtn];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
self.navigationItem.leftBarButtonItem = backButton;
My navigation bar size is 100 pixels tall, and when I use button position (0,0,35,32) it will work correctly. But in this case, the button is being displayed much lower than intended. What am I doing wrong?
self.btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnBack setImage:[UIImage imageNamed:#"back_active.png"] forState:UIControlStateNormal];
[self.btnBack addTarget:self action:#selector(back) forControlEvents:UIControlEventTouchUpInside];
self.btnBack.frame = CGRectMake(5, 9, 50, 30);
[self.navigationController.navigationBar addSubview:self.btnBack];
check this link also.
Update:for back button
-(void)back
{
[self.btnBack removeFromSuperview];
[self.navigationController popViewControllerAnimated animated:NO];
}
Try allocing backButtonView like this
UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35 , 32)];
Change : orgin of view to (0,0)
Edit
Try
backBtn.frame = CGRectMake(0, 0, 35, 32);
UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, -40, 35 , 32)];

Place custom view on Navigation Bar

I want to display Image,Title name,and two left right buttons. That I have done successfully.
Here is the code:
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 100)];
UIButton *leftButton = [[UIButton alloc]init];
[leftButton setImage:[UIImage imageNamed:#"previous-arrow.png"] forState:UIControlStateNormal];
[leftButton addTarget:self action:#selector(goPrevious:) forControlEvents:UIControlEventTouchUpInside];
[leftButton setFrame:CGRectMake(20, 50, 14, 13)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Title.png"]];
[imageView setFrame:CGRectMake(leftButton.frame.origin.x+leftButton.frame.size.width+4, 20, 50, 50)];
UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.frame.origin.x+imageView.frame.size.width+4, 30, 100, 40)];
NSString *cName = [NSString stringWithFormat:#"%#",[NameArray objectAtIndex:indexPath.section]];
[nameLabel setTextColor:[UIColor whiteColor]];
[nameLabel setBackgroundColor:[UIColor clearColor]];
[nameLabel setContentMode:UIViewContentModeScaleAspectFill];
[nameLabel setTextAlignment:UITextAlignmentLeft];
CGSize expectedLabelSize = [cName sizeWithFont:nameLabel.font
constrainedToSize:CGSizeMake(100, 40)
lineBreakMode:nameLabel.lineBreakMode];
[nameLabel setFrame:CGRectMake(imageView.frame.origin.x+imageView.frame.size.width+4, 35, expectedLabelSize.width, expectedLabelSize.height)];
nameLabel.text=cName;
UIButton *rightButton = [[UIButton alloc]init];
[rightButton setImage:[UIImage imageNamed:#"next-arrow.png"] forState:UIControlStateNormal];
[rightButton setFrame:CGRectMake(nameLabel.frame.origin.x+nameLabel.frame.size.width+4, 50, 14, 13)];
[rightButton addTarget:self action:#selector(next:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:nameLabel];
[view addSubview:imageView];
[view addSubview:leftButton];
[view addSubview:rightButton];
self.navigationItem.titleView = view;
This code is written in cellForRowAtIndexPath. The view is showing properly on navigation bar but after scrolling the tableview. Initially it is displaying on wrong coordinates.
Please Suggest.
Put this code in viewWillAppear or viewDidAppear. It's not meant to be in tableView protocol!

Action Sheets On The iPad

On the iPhone I like how action sheets take up the entire width of the screen and you can choose the height of it (so I can include other views). Here is my entire method that creates the action view (you probably on need the las few lines though)...
-(void)createActionView {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:#"Done",nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
UIButton *downHoleScore = [UIButton buttonWithType:UIButtonTypeCustom];
downHoleScore.frame = CGRectMake(93, 75, 35, 35);
[downHoleScore setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
downHoleScore.backgroundColor = [UIColor clearColor];
downHoleScore.tag=1;
[downHoleScore addTarget:self action:#selector(HoleScoreButtonTap:) forControlEvents:UIControlEventTouchUpInside];
[downHoleScore setBackgroundImage:[UIImage imageNamed:#"Left-Down-Arrow.png"] forState:UIControlStateNormal];
[actionSheet addSubview:downHoleScore];
UIButton *upHoleScore = [UIButton buttonWithType:UIButtonTypeCustom];
upHoleScore.frame = CGRectMake(193, 76, 35, 35);
[upHoleScore setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
upHoleScore.backgroundColor = [UIColor clearColor];
upHoleScore.tag=2;
[upHoleScore addTarget:self action:#selector(HoleScoreButtonTap:) forControlEvents:UIControlEventTouchUpInside];
[upHoleScore setBackgroundImage:[UIImage imageNamed:#"Right-Up-Arrow.png"] forState:UIControlStateNormal];
[actionSheet addSubview:upHoleScore];
golferScoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 70, 45, 45)];
golferScoreLabel.text = #"0";
golferScoreLabel.backgroundColor = [UIColor clearColor];
golferScoreLabel.font = [UIFont fontWithName:#"ChalkDuster" size: 45.0];
golferScoreLabel.textAlignment = UITextAlignmentCenter;
golferScoreLabel.shadowColor = [UIColor grayColor];
golferScoreLabel.shadowOffset = CGSizeMake(1,1);
golferScoreLabel.textColor = [UIColor whiteColor];
[actionSheet addSubview:golferScoreLabel];
CGRect pickerFrame = CGRectMake(0, 120, 0, 0);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet showFromRect:CGRectMake(0, 0, 320, 585) inView:self.view animated:YES];
}
How would I edit this to make it look more like an action view on the iPhone?
In this code...
[actionSheet showFromRect:CGRectMake(0, 0, 320, 585) inView:self.view animated:YES];
That above is where I think I am messing up how would I make this cover the entire bottom half of the screen on the iPad?
Read the docs on UIActionSheet. On iPad, they are presented in popovers.
If you want behavior like on the iPhone, I think you'll have to write your own actionSheet-like view and animations (which is really not that hard, it just takes a little time).
Anyway, presenting actionSheets on an iPad with the full width wouldn't be very good design anyway - you probably don't want buttons that are as wide as the whole screen. I would advise you to rethink your design.
But maybe you don't really want actionSheets. Maybe you only want that nice animation, to present some content of your own like that? That's certainly doable (see above), but then you have asked the wrong question.

uiview with animation

i want to bring a view to my view controller with a little animation.
some thing like the Facebook app.
i use this code to bring the uiview to the screen and i want to know how i can do it with little animation:
self.tmpView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, 330)];
self.tmpView.backgroundColor = [UIColor yellowColor];
UIImage *tmpImg = [UIImage imageNamed:#"d.png"];
UIImageView *tmpImgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
tmpImgView.image = tmpImg;
UIButton *returnBTN = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
returnBTN.frame = CGRectMake(10, 110, 100, 25);
returnBTN.backgroundColor = [UIColor clearColor];
[returnBTN setTitle:#"חזור" forState:UIControlStateNormal];
[returnBTN addTarget:self action:#selector(backPressed) forControlEvents:UIControlEventTouchUpInside];
UIButton *orderBTN = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[orderBTN setTag:tag];
orderBTN.frame = CGRectMake(130, 110, 100, 25);
orderBTN.backgroundColor = [UIColor clearColor];
[orderBTN setTitle:#"הזמן" forState:UIControlStateNormal];
[orderBTN addTarget:self action:#selector(orderPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.tmpView addSubview:tmpImgView];
[self.tmpView addSubview:returnBTN];
[self.tmpView addSubview:orderBTN];
[self.view addSubview:self.tmpView];
[UIView transitionFromView:viewToMoveOut toView:viewToMoveIn duration:timeOfDuration options:(option1 | option2 | ...) completion:^(BOOL finished){
if (finished){
// code when animation finished.
}
}];
How about this:
addSubview animation