Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>UIView as created opaque by default. When you set the backgroundColor to a pattern with transparency it is choosing black as the background color. You can set <code>customViewController.view.opaque = NO;</code> to allow the background of the view behind yours to show through.</p></li> <li><p>When you set the backgroundColor of the layer to a pattern with transparency you are bypassing the UIView logic, so the opaqueness of the view is ignored; so also is the the UIView's transform. CoreGraphics and friends use a coordinate system where the positive y-axis points upwards. UIKit flips this coordinate system. This is why the image appears upside down. </p></li> <li><p>If you add labels/views/buttons/etc. the will appear correctly on top of the layer's background pattern.</p></li> <li><p>When you set the view's background color it appears as if the layer's background color is indeed set. (I have not seen this documented anywhere).</p></li> </ol> <p>Essentially the UIKit's UIView stuff is a high-level interface which ends up rendered onto layers. </p> <p>Hope this helps.</p> <p>EDIT 5/7/2011</p> <p>You can get the image to show the right way up by flipping the layer's coordinate system BUT you shouldn't do this to view.layer; UIKit doesn't expect you to mess with this layer, so if your flip its coordinate system any UIKit drawing will be flipped; you need to use a sublayer.</p> <p>So your code would look like this:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; customViewController = [[CustomViewController alloc] init]; customViewController.view.frame = CGRectMake(213, 300, 355, 315); CALayer* l = [CALayer layer]; l.frame = customViewController.bounds; CGAffineTransform t = CGAffineTransformMake(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); l.affineTransform = t; l.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login_background.png"]].CGColor; [customViewController.view.layer addSublayer:l]; [self.view addSubview:customViewController.view]; } </code></pre> <p>Note: normally when you flip coordinates you include the height. For layers you don't need to do this. I haven't dug into why this is so. </p> <p>As you can see there is a lot more code involved here and there is no real advantage to doing it this way. I really recommend you stick to the UIKit approach. I only posted the code in response to your curiosity. </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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