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]];
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'
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.
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];
How to change the default gray background color of UIWebView to an image?
This is how you can set the background image:
self.webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:imagePath]];