Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I set my UIView's frame from CGRectMake?
    primarykey
    data
    text
    <p>I am new to iOS development, but have had an extensive crash course recently (BNR guid to iOS Programming). I am working on modally adding views to an app. I currently do not have a View Controller, so my AppDelegate's <code>application:didFinishLaunchingWithOptions</code> method looks as follows:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. MyUIView *map = [[MapSurface alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //this one does not work: MyUIView *map = [[MapSurface alloc] initWithFrame:CGRectMake(0, 0, 256, 256)]; [map setBackgroundColor:[UIColor grayColor]]; [[self window] addSubview:map]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } </code></pre> <p>After the view loads, I make a call to add a subview, but I cannot set the frame size using <code>CGRectMake</code>. It doesn't show up on screen. The only thing I have found to work is using the screen size, but this is not what I want. Here is the code for adding this subview:</p> <pre><code>UIImage *image = [[UIImage alloc] initWithCGImage:img];//img is a CGImageRef UIImageView *view = [[UIImageView alloc] initWithImage:image]; CGRect b = CGRectMake(0, 0, 256, 256); //[view setFrame:b];//nothing shows on screen //[view setBounds:b];//nothing shows on screen //[view setBounds:[[UIScreen mainScreen] bounds]];//shows the tan area in the graphic below [view setFrame:[[UIScreen mainScreen] bounds]];//fills the screen [map addSubView:view]; CGImageRelease(img); </code></pre> <p><img src="https://i.stack.imgur.com/p09Ea.png" alt="The tan area is not even filling the screen!"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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