reydanro / UIImageViewAligned

A UIImageView subclass which allows you to align the image left/right/top/bottom, even when contentMode is AspectFit.
MIT License
401 stars 69 forks source link

Set UIImage property not working #3

Open jasanchezsa opened 10 years ago

jasanchezsa commented 10 years ago

Hello, first congratulations for the project. Sorry for my English.

This code working:

UIImageViewAligned *imageAlign = [[UIImageViewAligned alloc] initWithFrame:CGRectMake(0, 0, 280, 280)];
[imageAlign setImage:[UIImage imageNamed:@"exampleImage.png"]];
imageAlign.contentMode = UIViewContentModeScaleAspectFit;
imageAlign.alignBottom = YES;
imageAlign.alignLeft = NO;
imageAlign.alignRight = NO;
imageAlign.alignTop = NO;
[self.viewContent addSubview:imageAlign];
[imageAlign setBackgroundColor:[UIColor greenColor]];

But when I use an image in memory that comes from another UIViewController is not working:

imageAlign.image = self.currentImage;

Thank you very much.

reydanro commented 10 years ago

What happens exactly? Is there no image displayed?

jasanchezsa commented 10 years ago

The Image displayed but aligment not working.

jasanchezsa commented 10 years ago
@interface OneViewController ()
@property (nonatomic, strong) UIImage *currentImage;
@end

@implementation OneViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [self setCurrentImage:[Image of camera picker];
}

- (void)pushTwoViewController
{
TwoViewController *twoVC = [[TwoViewController alloc] initWithNibName:@"TwoViewController" bundle:nil];
    [twoVC setCurrentImage:self.currentImage];
[self.navigationController pushViewController:twoVC animated:YES];
}

Second Controller:

@interface TwoViewController ()
@property (nonatomic, strong) UIImage *currentImage;
@end

@implementation TwoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

   UIImageViewAligned *imageAlign = [[UIImageViewAligned alloc] initWithFrame:CGRectMake(0, 0, 280, 280)];
[imageAlign setImage:self.currentImage]; 
imageAlign.contentMode = UIViewContentModeScaleAspectFit;
imageAlign.alignBottom = YES; //Not working!!!!! The image is center on UIImageView. My Image aspect ratio == UIViewContentModeScaleAspectFit
imageAlign.alignLeft = NO;
imageAlign.alignRight = NO;
imageAlign.alignTop = NO;
[self.viewContent addSubview:imageAlign];
[imageAlign setBackgroundColor:[UIColor greenColor]];
}

And I know the width and height of the image contained within the UIImageView