UIView Layer Bounds Not Showing Correctly

Discussion in 'iOS Programming' started by Zoyt, Feb 23, 2014.

  1. Zoyt macrumors newbie

    Joined:
    Jan 29, 2014
    #1
    I have a UIView who's size depends on the objects inside of it. However, when I attempt to retrieve the bounds of the UIView's layer, it returns the original size before it resized. Here's the code:

    Code:
    - (void) viewWillAppear:(BOOL)animated {
    [self.creditCount setText:@"This is a very long string"];
    [self.creditCount sizeToFit];
    
    CALayer *layer = self.creditCountView.layer;
    layer.shadowOffset = CGSizeMake(1, 1);
    layer.shadowColor = [[UIColor blackColor] CGColor];
    layer.shadowRadius = 4.0f;
    layer.shadowOpacity = 0.80f;
    layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];
    }
    In the code, creditCount is the text inside the view that resizes, and self.creditCountView is the view.

    In Interface Builder:
    [​IMG]

    When running:
    [​IMG]

    Thanks in advance.
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
  3. Zoyt thread starter macrumors newbie

    Joined:
    Jan 29, 2014
    #3
    I fixed it by putting the code that applies the shadow in the "viewDidLayoutSubviews" event.
     

Share This Page