How to put an image at a specific part of an UIImageVIew - ipad

i am very new on this platform and what i am trying is that show an UIImage of 50*50 size on UIImageVIew of 1024 * 768. But problem is that i want to show an image on CGRECTMAKE(10,60,50,50).position. means at a specific portion of an image.Please help me. Thanks in advance.

Not sure if this is what you're after - but have you tried using [UIImage drawInRect:] on the image?

Related

Show image of 10000x8000 pixels in iOS app

I'm trying to show image in my iOS APP.The image is of 10000x8000, which is much higher than iPhone's screen resolution, if I add it to UIImageView ,the APP will receive memory warnings and lead to crash.Can any one give me a advice about how to deal with it? Thanks a lot.
This is the sample app from apple which displays large size image, it uses TileImageView scale the image and reuse tiles according to present zoom.
https://developer.apple.com/library/ios/samplecode/LargeImageDownsizing/Introduction/Intro.html
Or if you simple want scale down the image, you could use this.
+ (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
This is just a side note and not an answer.
#AmitTandel's answer will surely help you but,
remember, you should not always request for this high resolution image instead you should implement a logic which stores this high resolution image to somewhere after reducing it using #Amit's answer. And then at the time of re-requesting for the same image url, you should first look up in to your stored directory, if that image not exist only then you may request for an image.
But yes, I'm not suggesting you to follow my answer as you will require to download this very high resolution sized image (which is actually none of use), so if you're getting this image from your server, you can ask them to give you reduced size for images. I've heard that, they can reduce images to different sizes to help apps showing specific images at variant places.

What size has a background image to have?

I'm developing a game in Swift (but not sprite kit), and i'm having a lot of trouble to make a background image that look great in every device. I recently understand the concept of the #1x, #2x and #3x images and it's pixels, but i can't find any place that say what size (width and height) an background image must have to look good both in canvas mode, preview mode and in action.
Anyone can help me?
For help, i'm attaching two print screens of a test that i made.
Thanks for the help :)
Image on Xcode 7 canvas
image in preview mode. Notice how he cut the edges
Size Icon For Devices:
UIImageView *imageView = [UIImageView alloc]init];
imageView.frame = CGRectMake(0,0,widthInt,heightInt);
imageView.image = [UIImage ImageWithName:#"nameImage.png"];

iOS UIImageView - Top of Image Chopped Off?

I'm new to iOS Development, I'm using a UIImageView to display an image. I've made a 320x480 and a 640x960 image called "red.png" and "red#2x.png".
No matter how I scale or align the UIImageView, the image always chops off half way at the top.
Is there something I'm meant to do to combat this, as I thought those resolutions were correct?
The UIImageView is sized at 320x568 to fill the storyboard.
Thanks :)
My comment above is hard to read, and it's probably an answer:
myImageView.contentMode = UIViewContentModeScaleAspectFit;
Try changing to image name as follows:
self.colourImage.image = [UIImage imageNamed: #"red.png"];
You should not directly specify '#2x' in image names.
It is automatically used if a device supports retina display.
That is why you need to create 2 sets of images; one for non-retina and one for retina (using #2x) and the OS selects the correct one for you.

How to do [UIImage resizableImageWithCapInsets:] prior to iOS5?

The following code tiles the image area within the specified insets:
UIEdgeInsets imgInsets = UIEdgeInsetsMake(10.f, 5.f, 13.f, 44.f);
UIImage *image = [[UIImage imageNamed:#"fileName"] resizableImageWithCapInsets:imgInsets];
However this is only available in iOS5. How can I achieve the same result for before-iOS5 compatibility?
[UIImage stretchableImageWithLeftCapWidth: topCapHeight:] is not appropriate as far as I understand, because it assumes that the tile-able area is 1px wide. In other words it doesn't tile, it streches. Therefore it doesn't work with patterns, only with single-color images. This is demonstrated in the screenshot below.
Then there is [UIColor colorWithPatternImage:], but this assumes that the entire image needs to be tiled, it doesn't allow for insets that must remain capped.
Any help appreciated, thanks.
.
I've been looking for a solution to this too. At this point I think I'll use respondsToSelector:#selector(resizableImageWithCapInsets:) on the original UIImage to see if the method is available. If not, then use stretchable image.
I'm still looking for a better solution, and if one comes up, I'll update the answer.

How to create a capped resizable image prior to iOS5

Does anyone know how to do this without using [UIImage resizableImageWithCapInsets:]? I'm trying to provide compatibility for users that cannot run iOS5.
UIEdgeInsets imgInsets = UIEdgeInsetsMake(10.f, 5.f, 13.f, 44.f);
UIImage *image = [[UIImage imageNamed:#"fileName"] resizableImageWithCapInsets:imgInsets]; // only available in iOS5+
Please note that I'm not looking to create a 1px stretchable image, I want to tile the area that is defined between the insets when the UIImage is resized. That is, [UIImage stretchableImageWithLeftCapWidth: topCapHeight:] does not do the trick.
Many Thanks!
You can't do this pre iOS 5 in the way you want unfortunately. The only option is [UIImage stretchableImageWithLeftCapWidth: topCapHeight:]. With it you have to specify a single pixel which gets tiled horizontally and vertically. Unfortunately there's no way to do what you want directly with UIImage pre iOS 5.
UPDATED: I've updated this answer because DTs was totally correct.

Resources