Why doesnt my background image show for iOS7 devices? - ios

I am trying to display the default image as the background of a iOS7 simulator, but its just white. It works on simulators that are older.
UIColor *image = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"Default.png"]];
self.view.backgroundColor = image;

Since Xcode was updated for iOS7, the image file #"Default.png" is no longer created with new projects. So unless you name a file #"Default.png" and put it in the project, the UIImage you create won't have the desired image attached to it.
Also, the #"Default.png" image is usually just a black background. You can achieve the same thing by simply setting the background color to black.
self.view.backgroundColor = [UIColor blackColor];

I tried your above code and seems to be perfect.i tried this on my device and its work perfectly while i also faced the issue of white background with simulator.I will suggest:-
1)reset the simulator and quit it.
2)re-run your project.
your issue will get solved.It works perfect..
Hope this will help you out.

I was using an asset catalog. This seemed to work.
UIColor *image = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"LaunchImage"]];
self.view.backgroundColor = image;

Related

How to change color of svg images in ios?

I want to change color of svg images. I am using following code, it hides the image and fill the whole image view with the color set.
self.badmintonImgView.tintColor = [UIColor orangeColor];
I need to change the color of image. Please suggest
If the SVG is in Assets.xcassets, you can tell Xcode to treat the image as an icon:
First, select your SVG image in the assets catalog
Then set the render mode to Template Image
Swift
To change the color of an SVG using Swift:
badmintonImgView.image = badmintonImgView.image?.withRenderingMode(.alwaysTemplate)
badmintonImgView.tintColor = UIColor.orange
This worked for me:
UIImage * imageOrange = [[UIImage imageNamed:#"yourSVGImageName"] imageWithTintColor:UIColor.orangeColor];
UIImageView * yourImageView = [[UIImageView alloc] initWithImage: imageOrange];
remember add the image to the assets folder.
I hope it helps you.
Do as follow may be work for you.
SVGKImage *svgImage = [SVGKImage imageNamed:#"YOURIMAGENAME"];
SVGKLayeredImageView *svgImageView = [[SVGKLayeredImageView alloc] initWithSVGKImage:svgImage];
[capturedImageView addSubview:svgImageView];
CALayer* layer = svgImageView.layer;
for (CALayer *subLayer in layer.sublayers) {
for (CALayer *subSubLayer in subLayer.sublayers) {
for (CALayer *subSubSubLayer in subSubLayer.sublayers) {
if( [subSubSubLayer isKindOfClass:[CAShapeLayer class]]){
CAShapeLayer* shapeLayer = (CAShapeLayer*)subSubSubLayer;
shapeLayer.fillColor = [UIColor BlackColor].CGColor;
}
}
}
}
Try this
[self.badmintonImgView setTintColor:[UIColor redColor]];
For publishing iOS 14.0+, I used אורי orihpt's answer, but realized I had to do some additional steps that differ from other answers on here. When using the Image, I couldn't get tintColor to work, but foregroundColor worked for me. I don't know if you're targeting the whole image, but this solution targets only the SVG paths, instead of creating a background color as well on the image (similar to Marcy's output image).
Image("imageName")
.foregroundColor(Color.red)

iOS9 and initWithPattern with iPad Pro causing repeating background

I now upgraded to iPad Pro simulator for iOS9 and now I am getting a repeating background. Is there something new I must do in order to get the image to correctly expand on iPad Pro. My image sizes dont have a new launch image so I am lost on this.
- (void)addBackgroundImage:(NSString*)imageName {
UIColor *image = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:imageName]];
self.view.backgroundColor = image;
}
Try to use the CGImage in background to avoid repeating background.
Objective-C
self.view.layer.contents = (__bridge id _Nullable)([UIImage imageNamed:#"backgroundImageAsset"].CGImage);
Swift
self.view.layer.contents = UIImage(named:"backgroundImageAsset").CGImage

Image not resizing properly to fit the screen

Im currently stylizing my login screen of my app, but I am running into a problem that i can't solve and is very odd... The image is not resizing properly and kind of starts to repeat itself, which i find very weird because i have the correct image sizes and have them correctly named, and i am calling them in my code correctly too, so i cannot find my problem. Below is the code.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"sl_login_default"]];
colorWithPattern is meant to create a pattern out of an image. If you want to have an image in the background, create a new UIImageView
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName];
backgroundImageView.frame = self.view.bounds;
[self.view addSubview:backgroundImageView];

iOS app - Apply background image object to UIView

Can anyone help me understand how I apply a background image object to a UIView please?
I have created a background image which is a blurred version of a background and I would like to apply it to be the background of a uiView in the foreground which would ideally mask the background image.
I have the following code so far -
_blurImage = [source stackBlur:50];
[_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:[_blurImage]]];
I would like to apply the image object(_blurImage) to be the background image of _hpBlurView but i'm struggling to get it working!
At first glance, you are using too many brackets. Here is a working version of your code :
_burImage = [source stackBlur:50];
_HPBlurImage.backgroundColor = [UIColor colorWithPatternImage:_blurImage];
I can't see what stackBlur:50 returns. So start from the beginning. colorWithPatternImag takes UIImage as a parameter. So Start by adding a picture, any picture, to your application. Lets imagine that the image is called image.png. This is one way to do it:
UIImage *image = [UIImage imageNamed:#"image.png"];
_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:image];
This should help to get you going.
Create an image and add to the background.:
UIImage *image = [UIImage imageNamed:#"youimage"];
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
It's that.
To make sure everything resizes properly, no matter rotation, device size and iOS version, I just set an UIImageView
//Create UIImageView
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.frame]; //or in your case you should use your _blurView
backgroundImageView.image = [UIImage imageNamed:#"image.png"];
//set it as a subview
[self.view addSubview:backgoundImageView]; //in your case, again, use _blurView
//just in case
[self.view sendSubviewToBack:backgroundImageView];

How do I create a textured background (image palette) color like grouped tableview background color?

I was wondering if anyone knows how to setup a new textured color in the palette. See the image below.
I tried to click on Other.... and then put a image palette on. like so:
So now I can select only one pixel out of it. I wish I could select more. It would make the work a lot easier instead of setting the background programatically every time.
If you have any suggestions of things I can try such as files to override or anything please help...
Thanks.
Programatically is kinda easy. But I'm making a universal app (iphone and Ipad) and... well there must be a way around it.
Here's how I do it programatically:
UIImage *wood = [UIImage imageNamed:#"woodenBack.png"];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:wood];
Can use something like this,
BOOL large = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad); // Page thumb size
if(large){
UIImage *wood = [UIImage imageNamed:#"woodenBack.png"];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:wood];
}else{
UIImage *brick = [UIImage imageNamed:#"brick.png"];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:brick];
}
if the background persists across all views then you can possibly apply the background to the UIWindow in your appdelegate and set background color clear color in the rest of the views.
Another approach is to loop and browse through the subviews and find tableview and apply background to the tableview, but I guess this is a CPU intensive task and it is better to have image loaded using code.

Resources