Question

I'm creating a custom view (a subclass of UIView), the purpose of which is to hold together a static background image, a static border/frame overlay, and several smaller images that can be rotated, stretched, and dragged around the view (before the whole view is exported as an image).

I'm stuck on displaying this custom view from within another view. The images are coming from the iPhone camera, which has a very high resolution, and the only things I have been able to manage so far are cutting off the majority of the image or having my view go over the end of the screen. I need to be able to display it alongside menu items and so on, without editing the image (so that it can be sent on in its full form).

I am also adding the image to a fullscreen view, and it still will not change size.

I am initialising the view with as follows

- (id)initWithImage:(UIImage *)image
{
    self = [super init];
    if (self) {
        [self setClipsToBounds:YES];
        [self setAutoresizesSubviews:YES];
        [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];

        _image = image;
        _imageView = [[UIImageView alloc] initWithImage:_image];
        [_imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
        [self addSubview:_imageView];
    }
    return self;
}

And I add it to another view with

self.card = [[SGImageCard alloc] initWithImage:[SGCardDataController cardImage]];
[self.cardPlaceHolder setAutoresizesSubviews:YES];
[self.cardPlaceHolder setContentMode:UIViewContentModeScaleAspectFit];
[self.cardPlaceHolder addSubview:self.card];

That view has also been set up in Interface Builder, and set there to autoresize its subviews and to cliptobounds (sometimes -- I have tried both ways). I have added my view in viewdidload (when the placeholder does not have its frame, for a reason I don't know), and also later, when it does (and it doesn't work either way).

What am I missing? (Have I even gone about this the right way?)

Was it helpful?

Solution

I finally solved this by setting the AutoResizeMasks to

UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleRightMargin | UIViewAutoResizingFlexibleBottomMargin

And also setting the ContentModes to

UIViewContentModeScaleAspectFit
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top