2016-01-31 79 views
0

我有一個自定義的UIView,我從一個xib文件加載時,在模擬器中運行時,視圖似乎被剪切在右側。 Iv'e試圖改變「view.autoresizingmask」中的屬性,但是使用可用的不同選項不起作用,也使用不同的約束選項也不能解決問題,自定義UIView不適合在屏幕的邊界Swift

我在swift文件中使用的代碼我的自定義視圖類是如下:

var view : UIView! 

override init(frame: CGRect) { 
    super.init(frame: frame) 
    loadViewFromNib() 
} 

required init?(coder aDecoder: NSCoder) { 
    super.init(coder: aDecoder) 
    loadViewFromNib() 
} 
func loadViewFromNib() { 
    let bundle = NSBundle(forClass: self.dynamicType) 
    let nib = UINib(nibName: "LeaderBoardView", bundle: bundle) 
    let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView 
    view.frame = bounds 
    view.autoresizingMask = [.FlexibleHeight, .FlexibleWidth] 
    self.addSubview(view); 

} 

This is an image of the xib file (Keep in mind the view that this xib is loaded into are the same dimensions as the file)

This image comes from the simulator and here you see how the view will not fit in the bounds of the screen.

SB:還存在着發生輕微渲染問題,也許有代碼可能有助於解決此問題。錯誤消息如下 「無法呈現LeaderBoardView的實例:渲染視圖花費的時間超過200毫秒,您的繪圖代碼可能會因性能下降而受到影響。」

回答

0

不要在loadViewFromNib創建視圖中再次,你已經添加在上面,剛:

view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView 

bundle可以nil