iOS adding a top bar as a subview - ios

I am currently working on an app for iPhone where I have an Imageview showing off some images and via swipe I can change the images.
But I'm currently trying to add a subview that will be a top bar, and when the image is touched, it will make this top bar slide down from the top.
The current code I've tried to do this with is:
CGRect frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 60.0f);
UIView *topBar = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:topBar];
[self.view bringSubviewToFront:topBar];
But the topbar won't show up, and I have logs showing that the touches are recognized.
How do I do this, and how do I properly populate the subview with buttons?
Best Regards.
FreeSirenety

Your topBar has nothing in it, so how can you know it has been added?
CGRect frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 60.0f);
UIView *topBar = [[UIView alloc] initWithFrame:frame];
topBar.backgroundColor = [UIColor redColor];
[self.view addSubview:topBar];
Also you don't need to use the bringSubViewToFront as the view that's gets added as a subview is always the topMost in the view hierarchy!

Related

Add a transparent view above an image view using objective c [duplicate]

This question already has answers here:
Replacing UINavigationControllers NavigationBar with UIView
(2 answers)
Closed 7 years ago.
i have a UIImageView .i want to add a trans
inCallBackGroundImgae = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"caller_texture.png"]];
[inCallBackGroundImgae setFrame:CGRectMake(0,top, self.view.frame.size.width, 250)];
[self.view addSubview: inCallBackGroundImgae];
i want to add a transparent view, where i add a red colour .i don,t want navigation bar i want to add a transparent view
Thanks in advance
Firstly hide navigation bar like this in viewDidLoad method
[self.navigationController.navigationBar setHidden:YES];
Now add your transparent UIView in place of navigationBar
UIView *transparentView = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 64)];
transparentView.alpha = 0.33f;
[self.view addSubview: transparentView];
EDIT : Adjust your image view frame as transparent view will not be seen.
CGRect imgViewRect = inCallBackGroundImgae.frame;
imgViewRect.origin.y = 64;
imgViewRect.size.height = decrease height here if necessary
inCallBackGroundImgae.frame = imgViewRect;
Please do this one
UIView *transView = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 50)];// set your height here what ever you wanna.
transView.alpha = 0.5f;// set your alpha how much you wanna transparent.
[inCallBackGroundImgae addSubview: transView];

ios to create view programmatically

I am trying to create a view like the below one programmatically but it covers the whole screen and does not be like this. There could be some thing size = Freeform, but could not find code on google to handle this.
UIView *picker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 260)];
picker.backgroundColor = [UIColor whiteColor];
Actually I want to create this whole view programmatically not though interface Builder.
please help
No other way than CGRectMake
if you want create the UIView that covers the whole screen
UIView *picker = [[UIView alloc] initWithFrame:self.view.bounds];
picker.backgroundColor=[UIColor blueColor];
[self.view addSubview: picker];
if you want create the UIView that not covers the whole screen
UIView *picker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 260)];
picker.backgroundColor=[UIColor blueColor];
[self.view addSubview: picker];
Create UIToolBar which has UIBarButtonItem(=Done).
Set the UIToolBar as UIDatePicker's inputAccessoryView.
You don't even need a backgroundView to add Done button and date picker.

Removing a UIView on connectionDidFinishLoading

I create a UIView inside the viewDidLoad event using the following code:
// add a white UIView
UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
whiteView.tag = 777;
whiteView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:whiteView];
This displays a white screen (view) to the user. Now, when the connection did finish loading the request I like to remove this view. I use the following code inside the connectionDidFinishLoading.
UIView *whiteView = [self.view viewWithTag:777];
[whiteView removeFromSuperview];
But for some reason the whiteView above is not getting removed and I see the white screen all the time. What am I doing wrong?

UIImageView shows outside its parents frame

I'm developing a iOs app for iPad and I'm implementing a UIImageView inside a UIView. The problem is that if the position of the image view has a position out of the UIView that it is inside, you can see it. The code:
UIView *vistafunda = [[UIView alloc] initWithFrame:CGRectMake(512/2, 48, 525, 651)];
[self.view addSubview:vistafunda];
vistafunda.backgroundColor = [UIColor darkGrayColor];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"hola.png"]];
img.center = CGPointMake(12, 200);
[vistafunda addSubview:img];
I would like that the image view was always under the view, so if the image is outside the view you could not see it.
Thanks!
Just make the containing view clip it's children
vistafunda.clipsToBounds = YES;

make a button that moves image

I want to make a button that moves my image one frame height up and if the button is pushed again move the image one frame height back down.
http://imageshack.us/photo/my-images/140/72197925.png/
(Illustration of the solution)
I am trying to use as little code as possible.
UIImage *image = [UIImage imageNamed:#"01bear.png"];
imageView = [[UIImageView alloc] initWithImage:image];
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:applicationFrame];
scrollView.contentSize = CGSizeMake(5760, 1);
[scrollView addSubview:imageView];
[window addSubview:scrollView];
[window makeKeyAndVisible];
scrollView.delegate = self;
scrollView.pagingEnabled = YES;
on button's touchUpInside event you need to change the:
scrollView.contentOffset = CGPointMake(X,Y);//required value to scroll the scrollview
if you only want the imageview to move, you can use:
[imageView setCenter:CGPointMake(X,Y)];//required value
Some questions:
Are you using the scroll view for other things, or just to get your image to move?
Do you want your image view to animate up, then down, or move suddenly?
A scroll view is awfully complex if all you want to do is have your view animate up, then down. To do that, you should look at the UIView class method animateWithDuration:animations: and it's variations.

Resources