I have an app,that contains UIImageView. it's working on iOS 8 but not showing image on iOS 7. I searched it, they always said that "it's auto layout problem." ok i removed all constraints on my view. but still not showing images.
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:sf._foto];
[Img setImage:[UIImage imageNamed:savedImagePath]];
Img.frame = CGRectMake(0,0,screenWidth,screenHeight);
If you are finding it is an autolayout issue, then you will need to remove the view from your xib and add it programmatically. I've had similar issues and just creating it programmatically, even if that means creating another xib with your view and loading it and adding it to your view's addSubview:
. Every view that I want to modify later, but don't want to deal with modifying constraints, I add programmatically.
Alternatively, you could add your constraints and then put outlets to them in your code to modify when you want to change things.
Hopefully this helps.
Don't know if this will help but this is how I saved and then accessed an image through the documents directory
- (void)savePaystubToFile: (UIImage *)image {
if (image != nil)
{
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * path = [documentsDirectory stringByAppendingPathComponent: @"example.png" ];
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
}
}
- (UIImage*)loadPaystub {
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * path = [documentsDirectory stringByAppendingPathComponent: @"example.png" ];
// If nothing is stored at that location then return nil
UIImage * image = [UIImage imageWithContentsOfFile:path] ? [UIImage imageWithContentsOfFile:path] : nil;
return image;
}
The main difference here seems to be me using the imageWithContentsOfFile function and the basic set up of the process step by step.
I don't know whether this is the issues which you are struggling with but this is a better way of separating the storage and retrieval of your image. If this is working correctly then you know that the problem will be in accessing the frame.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.