iOS9 and initWithPattern with iPad Pro causing repeating background - ios

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

Related

IOS 14 Images not showing in react native

I am unable to render Images on IOS 14 Simulator and Iphone
using Image from react-native and react-native-fast-image
It can display the image after adding [super displayLayer:layer]; if _currentFrame is nil if I understand correctly, _currentFrame should be for animated image, so if it is still image, we can use the UIImage implementation to handle image rendering, not sure if it is a correct fix.
react-native/Libraries/Image/RCTUIImageViewAnimated.m
if (_currentFrame) {
layer.contentsScale = self.animatedImageScale;
layer.contents = (__bridge id)_currentFrame.CGImage;
} else {
[super displayLayer:layer];
}

Changing background image for multiple platforms iOS

I'm still getting my feet wet when it comes to mobile development.
So I'm working on a .xib that has just a plain view controller in it. My graphic designer gave me 6 different background images as separate files to use. One for iPhone 4s, one for 5&5s, one for 6, one for 6+, one for non-retina iPads, and one for the retina iPads. The .xib and the images are in a CocoaPod that functions as a shared library between a few different apps that we make.
My question is this: How do I correctly determine which image to set as the background since the devices that the app can be run on all require different images?
What I've tried so far:
To get the device
-(NSString*)deviceName {
struct utsname systemInfo;
uname(&systemInfo);
//I set deviceType to the following return
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
And then quite a few if statements to set the background image:
if ([deviceType compare:#"iPhone3, 1"] == 0) {
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"iPhone_4"]]];
}
else if ([deviceType compare:#"iPhone5, 4"] == 0) {
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"iPhone_5"]]];
}
If you want specify different images for different screen sizes, one of solutions is name image with screen size height in the end.
For example image "DetailsBackground"
For iPhone 4, 4s - "DetailsBackground480"
iPhone 5, 5s - "DetailsBackground568"
iPhone 6 - "DetailsBackground667"
and so on
And then in code just load image according to your screen bounds:
NSString *imageName = [NSString stringWithFormat:#"BackgroundImage%.0f.png", [UIScreen mainScreen].bounds.size.height];
UIImage *backgroundImage = [UIImage imageNamed:imageName];
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
Another solution is using Image Assets.
But it more suitable to portrait/landscape and iPhone/iPad There you can use "Device Specific" + compact\regular\any widht+height in the image properties.
Please check attached screenshot:

iOS8 scale glitch when calling drawViewHierarchyInRect afterScreenUpdates:YES

I was converting a project from iOS7 to iOS8 which uses custom transitions and needs to capture the modal after it finishes loading afterScreenUpdates:YES and was seeing that the entire screen scale up for a second and scale back down. I also see this happening in the Flickr app for iOS between sections and on Yelp app when transitioning to a photo on iOS8.
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, 22.0);
[self.view drawViewHierarchyInRect:self.view.frame afterScreenUpdates:YES];
UIGraphicsEndImageContext();
Adding a larger scale factor helps emphasize the glitch more... but i'm just calling this on a button press in the example.
EDIT This appears to happen on iPhone 6 and 6 plus not on the 5.
Sample project github
Do you NEED it to draw after the screen updates? because I'm using:
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
and it seems to work fine on iOS7 and iOS8. I imagine this isn't a great solution for capturing images regularly (like multiple times a second) but it seems to work for a once off blur.
You have to provide #3x launch images for the 6 and 6 plus. The 6 being scaled at 750x1334, and the 6 plus image being scaled at 1242x2208.
Even it looks like bug in API, you can call drawViewHierarchyInRect with afterScreenUpdates set to NO to build snapshot AFTER screen updates if you use cunstruction like this:
typedef void (^CompletionHandlerWithId)(id result);
-(void)imageContaining:(CGRect)rect afterScreenUpdates:(bool)afterScreenUpdates opaque:(BOOL)opaque completion:(CompletionHandlerWithId)completion
{
bool success __block;
UIImage *snapshotImage __block = nil;
CompletionHandler block = ^{
// Create the image
UIGraphicsBeginImageContextWithOptions(self.bounds.size, opaque, [[UIScreen mainScreen] scale]);
success = [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:NO];
if (success)
{
snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect(
[snapshotImage CGImage],
CGRectMake(
snapshotImage.scale*rect.origin.x,
snapshotImage.scale*rect.origin.y,
snapshotImage.scale*rect.size.width,
snapshotImage.scale*rect.size.height));
// or use the UIImage wherever you like
snapshotImage = [UIImage imageWithCGImage:imageRef scale:snapshotImage.scale orientation:UIImageOrientationUp];
CGImageRelease(imageRef);
}
UIGraphicsEndImageContext();
if (completion)
{
if (! success)
{
NSLog(#"Error: [UIView drawViewHierarchyInRect] failed on %#", self);
(completion)(nil);
}
else
{
NSLog(#"Success: [UIView drawViewHierarchyInRect] on %#", self);
(completion)(snapshotImage);
}
}
};
if (afterScreenUpdates)
[CATransaction setCompletionBlock:^{
(block)();
}];
else
(block)();
}
This bug also exists when you run on an iPad2 running iOS7.
Fix: set afterScreenUpdates: to NO
My app has some moving UIButtons, so I don't allow the blur transition until after the movement has stopped. As far as I have found so far, there is no difference in YES or NO.
Appears to be fixed in iOS9 / XCODE 7 builds
I found a solution for me to solve this problem.
I add #3x launch images to my project. And choose launch Screen file to "Main".
This will make app run at original resolution, smaller bounds when run at iphone6, but not glitch when calling drawViewHierarchyInRect. Like this.
Then, scale my view to fullscreen when viewDidLoad.
- (void)viewDidLoad{
[super viewDidLoad];
UIScreen *mainScreen = [UIScreen mainScreen];
CGRect tempFrame=mainScreen.bounds;
double aspect=tempFrame.size.width/320;
self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, aspect, aspect);
}
Hope helpful :)

Why doesnt my background image show for iOS7 devices?

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;

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];

Resources