2012-11-21 160 views
1

我不確定我是否缺少某些東西,但是應該是一個簡單的任務,但不想工作。我試圖在iOS 6中添加投影到UIView。我正在使用故事板和自動佈局。我正在繪製帶有白色背景的故事板場景中的UIView。然後將其鏈接到IBOutletUIView陰影不顯示

在我.h文件中

我宣佈IBOutlet和財產

#import <UIKit/UIKit.h> 

@interface LoginViewController : UIViewController { 

    IBOutlet UIView *_loginPanel; 

} 

@property (nonatomic, retain) IBOutlet UIView *_loginPanel; 

@end 

,並在我的.mi import QuartzCore

#import <QuartzCore/QuartzCore.h> 

Synthesize財產

@synthesize _loginPanel; 

並執行以下操作在我的ViewDidLoad方法

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIBezierPath *path = [UIBezierPath bezierPathWithRect:_loginPanel.bounds]; 

    _loginPanel.layer.masksToBounds = NO; 
    _loginPanel.layer.shadowColor = [UIColor blackColor].CGColor; 
    _loginPanel.layer.shadowOpacity = 0.7f; 
    _loginPanel.layer.shadowOffset = CGSizeMake(-5.0f, -5.0f); 
    _loginPanel.layer.shadowRadius = 8.0f; 
    _loginPanel.layer.shadowPath = path.CGPath; 
    _loginPanel.layer.shouldRasterize = YES; 
} 

但我沒有得到陰影只是白色UIView我在故事板中定義。

任何幫助將不勝感激。

感謝,

理查德

+0

你給出口(引用)到UIView? –

+1

@ spill50你的代碼是完美的工作。我認爲你的自定義視圖大小比你的父視圖大。否則你的插座沒有連接。 –

+0

@ spill50你的代碼工作正常只是檢查你給出口(Referance)的_loginPanle或不.. –

回答

1

也許你可以改變這一行:

UIBezierPath *path = [UIBezierPath bezierPathWithRect:_loginPanel.bounds]; 

有:

CGPathRef path = [UIBezierPath bezierPathWithRect:_loginPanel.bounds].CGPath; 

和關閉過程中shadowPath行中刪除 「.CGPath」 。

也許你可以嘗試在viewDidAppear方法中做這個,看看它是不是一個調整大小的問題。

+0

我將它移動到viewDidAppear方法並且它可以工作。 :)它必須與調整視圖的約束有關。感謝所有我以爲我瘋了。 –