Why the webview has the gray background and smaller than the UIWebVIew - xcode

here is my code ,the amazon web page is smaller than the webview , and has a gray background
self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)];

because UIWebView has extra space for status bar. you can disable status bar and extra space will hide.
in case status bar use this code to hide space:
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
gray color is UIWebView default background color, you can change it:
self.webView.backgroundColor = [UIColor redColor];

Related

Drawing correct CALayer colors honoring NSAppearance

I am looking into theming my app by setting window.appearance.
In my app, I draw some stuff inside layers. I also use Core Plot, which renders its charts in layers.
For the default aqua appearance, I just use the system colors (such as NSColor.textColor and NSColor.gridColor) and they are drawn in the correct color in CALayer. But changing the window's appearance to vibrant dark causes colors to be drawn incorrectly.
Is there any way to obtain the correct color for a givenNSAppearance? Private API is acceptable too.
If the question is not clear, here is a very simple example to show the problem.
I set up a CATextLayer that is added as a sublayer of the main view's sublayers and an NSTextFied that is added as a subview:
CATextLayer* textLayer = [CATextLayer new];
textLayer.string = #"Is this colored correctly? (Layer)";
textLayer.foregroundColor = NSColor.textColor.CGColor;
textLayer.contentsScale = 2.0;
textLayer.frame = (CGRect){0,0, [textLayer preferredFrameSize]};
NSTextField* textField = [NSTextField new];
textField.stringValue = #"Is this colored correctly? (View)";
textField.textColor = NSColor.textColor;
textField.font = (__bridge id)textLayer.font;
textField.editable = NO;
textField.selectable = NO;
textField.bezeled = NO;
textField.backgroundColor = nil;
[textField sizeToFit];
textField.frame = (CGRect){0, 60, textField.bounds.size};
[self.view.layer addSublayer:textLayer];
[self.view addSubview:textField];
On an Aqua window, both appear correctly:
However, on a dark vibrant window, the layer does not, while the text field does:
I'd like to know how to get the correct color for a given NSAppearance.
So I had an incorrect approach.
The right way to do it, is to implement -updateLayer in the view and take the colors' CGColor snapshot there. -updateLayer is called when the appearance changes, so the view can update it with the correct color values.

Send UIImageView (label background) to back to display UILabel

I am trying to add an image as a background to a UILabel, but my UILabel's title cannot be seen, even though I tried to send the background image to the back. My code is below and any advice on how to help with this would be great, thanks!
UIImageView *labelBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image.png"]];
[myLabel addSubview:labelBackground];
[myLabel sendSubviewToBack:labelBackground];
myLabel.backgroundColor = [UIColor clearColor];
[myLabel setText:title];
When you add a view (your image view) as a subview to another view (your label), the subview will always be in front of its superview. They would either need to be siblings:
[myContainer addSubview:labelBackground];
[myContainer addSubview:myLabel];
or better yet, the label should be a subview of the image view:
[labelBackground addSubview:myLabel];
[myContainer addSubView:labelBackground];
Another solution might be to use your image as a background color for your label:
[myLabel setBackgroundColor:[UIColor colorWithPatternImage:myUIImage]];
But note that the image will be repeated instead of centered or stretched.
Try adding the UILabel as a subview of the UIImageView, rather than the other way around.
This will result in the UIImageView being the "container" of the label, and thus the label being on top of the UIImageView.

How to make TabBar transparent

I want to make the tabbar transparent and leave the icons still there. So that when you look at it the icons on the tabbar look like they are their by themselves. Whats the code for me to do this? Right now this is the code i have
UIImage* tabBarBackground = [UIImage imageNamed:#""];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#""]];
Try this code
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, 48);
UIView *trans_view = [[UIView alloc] initWithFrame:frame];
[trans_view setBackgroundColor:[[UIColor alloc] initWithRed:0.0
green:0.0
blue:0.0
alpha:0.5]];//you can change alpha value also
[tabBar1 insertSubview:trans_view atIndex:0];//tabBar1 = your tabbar reference
[trans_view release];
}
this link also will help you
The easiest way to make a tab bar transparent is by setting the tab bar background image to a transparent image in the interface builder.
You can get a transparent png image whose height and width is equal to the tab bar's from the net.
Note: By changing the alpha value, you actually end up dimming the tab bar's icons as well. Make sure this is what you want, otherwise using a transparent background image is a better option.

iOS Colorwithpattern - using a custom iPhone5 image

For my app's loading screen and splash screen, I used up with two different methods to display my iPhone 3, iPhone 4 and iPhone 5 images appropriately.
For the loading screen, simply adding -568h#2x to your image is enough to support iPhone5.
For the splashscreen, I used a series of (if height == ) cases to check the height of the UIScreen's bounds and sourced the appropriate image to the image view. It was apparent to me here that the -568h isn't universally recognized as an iPhone 5 image. It is only applicable to the loading screen.
Now, in my AppDelegate, I'm setting a the background image. All my subviews have a transparent background, so they are supposed to show through to the background image. However, I am having the most trouble setting up the background image here.
Simply passing in the "Background.png" Adding the -568h#2x to the end of the filename does not work. It will do the non-retina and the 3.5'' retina display, but will not pick up for the 4'' display.
ie:
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background.png"]];
If I use the above snippet of code, the iPhone4 picture is used instead of the iPhone5 picture and this is not what I want.
I moved onto trying to do the same thing as I did with the splashscreen. I had a bunch of if cases:
CGFloat height = [UIScreen mainScreen].currentMode.size.height;
if ( height == 1136 )
{
//Choose image here
}
else if (height == 960)
{
//Choose image here
}
else if (height == 480)
{
//Choose image here
}
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:chosenImage]];
But the colorWithPatternImage function thinks that the chosenImage goes by 1 point = 1 pixel. So I end up with a non-retina picture attempting to fit onto the iPhone 5 screen. What exaclty does it look like? Looks like only the top left quadrant of the image I wanted is displayed over the entire iPhone 5 screen. It looks like no retina scaling was applied.
I need the iPhone to recognize that I have a retina-friendly iPhone 5 picture to be used as the background. How do I do this?
I found this code here, perhaps it helps you:
UIImage *tmpImage = [UIImage imageNamed:#"background-568h#2x.png"];
UIImage *backgroundImage = [UIImage imageWithCGImage:[tmpImage CGImage]
scale:2.0
orientation:UIImageOrientationUp];
self.window.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];

UINavigationBar with image and default gradient background with iOS5

I'm attempting to use the new [UINavigationBar appearance] functionality in iOS5 to add a logo image to the UINavigationBars in my application. Primarily, I'd like to keep the default gradient, but center a transparent png in the NavBar. The logo image is roughly 120 pixels wide (240 pixels#2x).
I have first attempted this by setting the background image. The default behavior for setBackgroundImage:forBarMetrics: appears to be to tile the image, and all transparent parts show the default navbar background color, black. I can also set the background color via the appearance modifier, and get a flat color background, but I'd really like to get the original gradient behavior without maintaining a separate image resource for it. It also makes it easier to adjust in code, since I can adjust the tint there, rather than re-generating a new image if I decide to change it.
What I'm trying to use:
UIImage *logoImage = [UIImage imageNamed:#"logoImage"];
[[UINavigationBar appearance] setBackgroundImage:logoImage forBarMetrics:UIBarMetricsDefault];
You can do this two ways. If you want to always have the image in the navigation bar, then create an image view and set it as a subview of the navigation bar:
[self setLogoImageView:[[UIImageView alloc] init]];
[logoImageView setImage:[UIImage imageNamed:#"logo.png"]];
[logoImageView setContentMode:UIViewContentModeScaleAspectFit];
CGRect navFrame = [[navController navigationBar] frame];
float imageViewHeight = navFrame.size.height - 9;
float x_pos = navFrame.origin.x + navFrame.size.width/2 - 111/2;
float y_pos = navFrame.size.height/2 - imageViewHeight/2.0;
CGRect logoFrame = CGRectMake(x_pos, y_pos, 111, imageViewHeight);
[logoImageView setFrame:logoFrame];
[[[self navigationController] navigationBar] addSubview:logoImageView];
If you only want to display the logo in a certain view, then set the view's navigation item:
[logoImageView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[[self navigationItem] setTitleView:logoImageView];

Resources