Is there a way to tell an imageView to stop loading a remote image?
This would be an image loaded with the image property of an imageView
I figured it out by setting the imageView.image = null;
Related
I have picked a menu image that I want to implement on the navigation bar. The image is 120x92 pixels and the resolution is 72.
UIImage *menu = [self imageWithImage:[UIImage imageNamed:#"menu.png"] convertToSize:CGSizeMake(45, 34.5)];
self.navigationItem.leftBarButtonItem.image = menu;
The problem is that the menu image seems very blurry. What might be the reason/s for bad image quality? How can I fix it? Thank you!
I have a UIImageView and when I set an image in that view using IB, the image is the correct size when I run the app (40x40). When I programmatically change the image using the code below, the new image is 400x400 or so. This is using the same image that I know works fine if it's set in IB. Do I have to scale the image before I add it to the UIImageView? I assumed auto-layout's constraints would automatically do this for me.
UIImage *messageTypeImage = [UIImage imageNamed:message.imageName];
[messageCell.imageView setImage:messageTypeImage];
[messageCell.contentView layoutIfNeeded];
The UIImageView's content mode is set to "Scale To Fill" and I've tried adding the code below both before and after calling setImage:
[messageCell.imageView setContentMode:UIViewContentModeScaleAspectFill];
[messageCell.imageView setClipsToBounds:YES];
Here's how the constraints are set up for the image view:
Are you using iOS 8 SDK? If so, try overriding layoutSubviews in your cell subclass and add this:
self.contentView.frame = self.bounds;
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
There are some problems with the contentViews' of collection view/table view cells constraints/masks.
Wow. Finally found the answer here. Turns out, there's a default imageView outlet in prototype cells. I was unknowingly using that outlet and not the UIImageView I thought I was using.
My current problem is that when i try rotating a UIImageView it rotates but it resizes too.
Here's the code i'm using:
CGAffineTransform a = _player.image.transform;
_player.image.transform = CGAffineTransformRotate(a, angle);
_player is a Player object and image is a Player UIImageView variable.
Thanks for the tip.
EDIT:
pic 1: Application launched
enter link description here
i can move a player by touching it and using the pad
pic 2: i want to move the car and rotate it as the pad but the car resizes and doesn't move.
enter link description here
Any ideas?
set autoResizingMask of the view property to UIViewAutoresizingMaskNone
Try turn off "Autoresize Subviews" attribute (in the XIB file) for superview of the UIImageView. You can found this answer here too: UIView resizing but not the SubViews .
how do you use UiimageView to show an image to make sure the imageview is the correct size of the UIImage? thanks!
This code should create an imageView with the frame of your image automatically.
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"ImageName"]];
A little background from the docs.
This method adjusts the frame of the receiver to match the size of the
specified image. It also disables user interactions for the image view
by default.
I have three files : background~ipad.png, background#2x~iphone.png & background~iphone.png
When I set the background image I use:
[self.background setImage:[UIImage imageNamed:#"background.png"]];
Is there any way for me to verify that background#2x~iphone.png is the file being loaded when I run the retina screen simulator? Because it looks (ocularly) like it's background~iphone.png that's being loaded...
Try temporarily changing the content of the images to verify that the correct image gets loaded. For example make the background~ipad.png solid blue and the background~iphone.png solid green. That way you will see if the right one is loaded.
You could check the size of the image before you set it:
UIImage *backgroundImage = [UIImage imageNamed:#"background.png"];
NSLog(#"%#",NSStringFromCGSize(backgroundImage.size);
[self.background setImage:backgroundImage];
Also, I would remove ~iphone extension, just use background and background#2x, then either use ~ipad or use the UI_USER_INTERFACE_IDIOM() macro to detect iPad and set a different image altogether.