I'm trying to align an imageView at the bottom of my UIViewController, but on iPhone 5 simulator it isn't aligned on the bottom.
I've tried to put an imageView at the bottom of the storyboard and it is aligned correctly so I guess I miss something in my code.
Any advice?
Thanks,
e.
imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 416, 320, 64)];
[imageView setContentMode:UIViewContentModeScaleToFill];
imageView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:imageView];
got it, used
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:[xmlView]|"
options:0
metrics:0 views:NSDictionaryOfVariableBindings(xmlView)]];
Set the Frame Size like this:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.size.height-64, 320, 64)];
[imageView setContentMode:UIViewContentModeScaleToFill];
[self.view addSubview:imageView];
Hope this will help.
Related
Does anybody know, how I can make the UINavigationBar solid black in IOS7? Default it is white, and I need it black.
If you're targeting only iOS 7 you can use:
[[UINavigationBar appearance] setBarTintColor:(UIColor *)];
Here is one way that creates a black UIImage programmatically and sets it for the UINavigationBar's appearance:
UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 568, 44)];
background.backgroundColor = [UIColor blackColor];
UIGraphicsBeginImageContext(background.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[background.layer renderInContext:context];
UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[UINavigationBar appearance] setBackgroundImage:backgroundImage
forBarMetrics:UIBarMetricsDefault];
found it by myself. Go into storyboard-designer, select the ViewController, go to attribute inspector and change Top Bar from inferred to 'Opaque black navigation bar'
Hey guys, I appear to have run into a problem. I have an application (View-based) that has a UITableView displayed on the bottom half of the screen, with the selection of a cell then bringing up a custom cell taking up the bottom of the screen. I have a "more info" button on the bottom right of this cell, and and when it is selected, I wish for it to open a new NIB file, however the only thing I can manage to do is remove the tableView from the screen..I am not sure of what to use before the "addSubview" because it is not self.view which I thought it would be.
- (void)moreInfoButton:(id)selector{
NSLog(#"Button Pressed");
MoreInfo *mivc = [[MoreInfo alloc] initWithNibName:#"MoreInfo" bundle:nil];
[self.tableview removeFromSuperview];
//[self.view addSubview:(UIView *)mivc];
[self.navigationController pushViewController:mivc animated:YES];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"List of Events" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[mivc release];
}
Also, the (UIView *) doesn't do the trick either. Any suggestions?
P.S. The UITableView does not use a navigationController at all, it is just the table, would this be the problem?
Also, what if I chose to just push a new view, and not use the navigationViewController for this view, is this possible?
I can't answer your navigation controller question without seeing more of your program. To answer your other question, without using a navigation controller you can just add a new view with:
newViewVC = [[NewViewVC alloc]initWithNibName:#"NewViewVC" bundle:nil];
[self.view addSubview:newViewVC.view];
Typically newViewVC is declared in your .h so you can release it later.
I have found an easy way: pushing it as a modal.
- (void)moreInfoButton:(id)selector{
NSLog(#"Button Pressed");
MoreInfo *mi= [[MoreInfo alloc] initWithNibName:#"MoreInfo" bundle:nil];
[self presentModalViewController:mi animated:YES];
}
All that is needed is a back button in the new nib file.
I am building an ap in which I need to remove the present view from the superView and load another one. But the new loaded view shifts upward. Also when the firstView is again loaded, it loads perfectly.
Could anyone possible suggest something to get rid of this issue.
Following is the method I am using to flip the view to secondView
-(void) flipToBack
{
CreateMessageViewController *oSecondView = [[CreateMessageViewController alloc] initWithNibName:#"CreateMessageViewController" bundle:nil];
[self setMsgViewController:oSecondView];
[oSecondView release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
Thanks in advance!!
Looking forward to your kind responses.
thanks
There is not much I can tell without looking at the big picture. Check the frames in the IB to see if they are correctly set.
Is this code from your appDelegate? Does viewController have a toolbar shown on his view? Maybe your view is shifted the exact pixels your toolbar height is?
Got it.
It's happening due to the IB settings. So in IB your viewController has a statusBar and your view has a height of 460 (for iPhone) not 480. The 20 points are the statusBar height. When transitioning to the second view, its rect is {0,0,320,460} so the view is positioned behind the application's statusBar and you are missing 20 points from the bottom.
To get around this you need to:
Go into IB and set the CreateMessageViewController's statusBar to Unspecified.
Go into the view size section and set the view's height to 480 (for iPhone).
Now your CreateMessageViewController's view will show properly.
After long time playing around with the code and IB, I found the bug. It was corrected as
Open the mainWindow.xib and add the UIViewController Object from the Library. Change its class to your Class that handles the specified viewController and then comes the click. Go to the properties section of the Attribute Inspector and set the respective Nib Name for the Controller and now save and exit the IB.
And the code changes to
-(void) flipToBack
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
Thanks to all who responded!!
I want to change the UIWebView zoom level programmatically.
I have tried these but they are not worked for me ;
UIScrollView *sv = [theWebView.subviews objectAtIndex:0];
[sv setZoomScale:50 animated:YES];
also,
[theWebView stringByEvaluatingJavaScriptFromString:#"document.body.style.zoom = 5.0;"];
Any idea?
This is the only way I could find to accomplish it:
(specify your own sizes if you wish, i was attempting to zoom out after typing into a form field)
UIScrollView *sv = [[webViewView subviews] objectAtIndex:0];
[sv zoomToRect:CGRectMake(0, 0, sv.contentSize.width, sv.contentSize.height) animated:YES];
I would use:
UIScrollView * sv = self.theWebview.scrollView;
[sv setZoomScale:50];
where self is the viewController containing the webView.
Your problem could be the size of your zoomScale exceeds the size of sv.maximumZoomScale.
UIScrollView * sv = yourwebview_outlet.scrollView;
[sv setZoomScale:50];
Is it possible to place an image in the UIWebView background instead of that gray default color. If yes then how?
Did it by myself.
self.webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:backgroundImage]];
In your viewDidLoad please Add this code for loading image at startup
[webView setOpaque:NO];
webView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"night.jpg"]];
self.webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:imagePath]];