Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my attempt to display an image over the background causing a white display?
    text
    copied!<p>I have a background coming from Default-568h@2x.png. I want to display a shrunk PNG over part of the background, but calling:</p> <pre><code>[[CJSHCardView alloc] initWithScale:.1]; </code></pre> <p>turns the display white. This does not happen if I comment this line, but in the function call, even if I make it return immediately it turns the display white after half a second:</p> <pre><code>- (id)initWithScale:(float)scale { UIImage *img = [UIImage imageNamed:@"note.png"]; self = [super initWithImage:img]; if (self != nil) { self.frame = CGRectMake(0, 0, img.size.width * scale, img.size.height * scale); UIImageView *myImage = [[UIImageView alloc] initWithFrame:self.frame]; myImage.opaque = NO; [self addSubview:myImage]; } return self; } </code></pre> <p>Moving/copying the return statement to be the first in initWithScale makes no discernible change from how it is with the return statement properly at the end: a brief view of the background, followed by a white screen. note.png is in "Supporting Files".</p> <p>Do you see any gotchas where I can change things so that a shrunken version of the note (maintaining aspect ratio) displays? The note.jpg image does not have a pixel of white.</p> <p>Thanks,</p> <p>--EDIT--</p> <p>Regarding the first comment:</p> <pre><code>@implementation CJSHCardView : UIImageView - (id)initWithFrame:(CGRect)frame { NSAssert(NO, @"Call initWithHeight instead."); return self; } </code></pre> <p>Does that answer your question?</p> <p>--SECOND EDIT--</p> <p>Thank you for your response and your code, Nick. I have slightly altered it to fit ARC and to initially set a fixed-width scale, but I was a little unsure of what method to put it in. I tried the ViewController's viewDidLoad() method, but that resulted in the background being shown without hide or hair of the note. My present viewDidLoad() method reads:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIImage *backgroundImage = [UIImage imageNamed:@"Default-568h"]; CGRect containerRect = CGRectZero; containerRect.size = [backgroundImage size]; UIView *containerView = [[UIView alloc] initWithFrame:containerRect]; float scale=.1; UIImageView *backgroundView = [[UIImageView alloc] initWithImage:backgroundImage]; [containerView addSubview:backgroundView]; [backgroundView sizeToFit]; // [backgroundView release]; UIImage *noteImage = [UIImage imageNamed:@"note"]; CGSize noteSize = [noteImage size]; UIImageView *noteView = [[UIImageView alloc] initWithImage:noteImage]; [noteView setContentMode:UIViewContentModeScaleAspectFit]; [noteView setFrame:CGRectMake(0, 0, noteSize.width * scale, noteSize.height * scale)]; [containerView addSubview:noteView]; // [noteView release]; } </code></pre> <p>Thanks,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload