UIView Layer Bounds Not Showing Correctly

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

  1. Zoyt macrumors newbie

    Jan 29, 2014
    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:

    - (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:

    When running:

    Thanks in advance.
  2. xStep macrumors 68000

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

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

Share This Page