2014-02-22 43 views
0

我有一個UIView,它的大小取決於它內部的對象。但是,當我嘗試檢索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是視圖。

在Interface Builder:

In IB

當運行:

When running

在此先感謝。

回答

0

我通過在「viewDidLayoutSubviews」事件中放置應用陰影的代碼來修復它。這樣,每次大小改變時,陰影都會更新。