문제

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:

In IB

When running:

When running

Thanks in advance.

도움이 되었습니까?

해결책

I fixed it by putting the code that applies the shadow in the "viewDidLayoutSubviews" event. That way, every time the size changes, the shadow updates.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top