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?
Related
I have this code in viewDidLoad:
[self.navigationController setNavigationBarHidden:YES];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.view.backgroundColor = [UIColor whiteColor];
//we need to add white background behind the status bar
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
UIView* statusBarWhiteBackGround = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, statusBarHeight)];
[statusBarWhiteBackGround setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:statusBarWhiteBackGround];
UIView * redBackGroundColor = [[UIView alloc] init];
[redBackGroundColor setBackgroundColor:[UIColor redColor]];
redBackGroundColor.frame =CGRectMake(0,statusBarHeight , self.view.frame.size.width, self.view.frame.size.height-statusBarHeight);
[self.view addSubview:redBackGroundColor];
statusWhiteBackGround view is used to change the color of the status bar.
here is the result of the above code:
but when the app enter background and then back to foreground, the redBackGroundColor view change it's orging.y as you can see in the bellow picture:
what's the problem ?thanks
Create a UIView programatically on method
-(void)viewDidLayoutSubviews{
screen=[[UIScreen mainScreen] bounds];
//Simple view
self.customView = [[CustomAlertOKView alloc]initWithFrame:CGRectMake(0, 20, screen.size.width, screen.size.height)];
[self.view addSubView:customView];
}
or
Create a view using storyboard and set the x as 0, y value as 20,width and height based on the screen size
#IBOutlet UIView *customView;
set the outlet in the storyboard,
Then set the background color of the custom view to redcolor and main view to white color
self.view.backgroundColor = [UIColor whiteColor];
customView.backgroundColor = [UIColor redColor];
I wanted to add a background image to my UIViewcontroller in my iOS app.
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[imageView setImage:[UIImage imageNamed:#"background"]];
[self.view addSubview:imageView];
}
This unfortunately produced a result where the whole screen was covered.
Is there a way to move this subview to the bottom layer so that it doesn't cover my buttons and textfields?
You need to insert the view at the bottom of the hierarchy
[self.view insertSubview:imageView atIndex:0];
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.
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!
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;