Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Zoyt

macrumors newbie
Original poster
Jan 29, 2014
4
0
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:
ab1K3.png


When running:
O2HAV.png


Thanks in advance.
 
I fixed it by putting the code that applies the shadow in the "viewDidLayoutSubviews" event.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.