Cocoa touch UIView图层边界未正确显示

Cocoa touch UIView图层边界未正确显示,cocoa-touch,calayer,shadow,Cocoa Touch,Calayer,Shadow,我有一个UIView,它的大小取决于其中的对象。但是,当我尝试检索UIView层的边界时,它会返回调整大小之前的原始大小。代码如下: - (void) viewWillAppear:(BOOL)animated { [self.creditCount setText:@"This is a very long string"]; [self.creditCount sizeToFit]; CALayer *layer = self.creditCountView.layer; layer.sh

我有一个UIView,它的大小取决于其中的对象。但是,当我尝试检索UIView层的边界时,它会返回调整大小之前的原始大小。代码如下:

- (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];
}

在代码中,creditCount是调整大小的视图中的文本,self.creditCountView是视图

在界面生成器中:

运行时:


提前感谢。

我通过在“viewDidLayoutSubviews”事件中应用阴影的代码修复了它。这样,每次大小更改时,阴影都会更新