2014-10-30 27 views

回答

1

你必須創建一個自定義類的基礎上的UIView。這個類聲明爲@IBDesignable並且具有@IBInspectable屬性。覆蓋UIView.drawRect(),並且完全免費顯示您的視圖。

這是一個示例類,讓你開始。

import UIKit 

@IBDesignable 
class MyTabView: UIView { 
    @IBInspectable tabTitle: String = "" 
    @IBInspectable tabColor: UIColor = UIColor.clearColor() 

    override init(frame: CGRect) { 
     super.init(frame: frame) 
     // Initialization code 
    } 

    required init(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
    } 

    override func prepareForInterfaceBuilder() { 
     // stuff for interface builder only 
    } 

    override func drawRect(rect: CGRect) 
    { 
     // this is where your view gets drawed 
     self.layer.cornerRadius = 10 
     self.layer.masksToBounds = true 
    } 
} 
+0

太棒了!它的工作。 – tounaobun 2014-10-31 01:51:30

+0

還有一個問題,我爲這個自定義視圖添加了一個相應的xib,並且我在這個xib中添加了一些UIControls,當我在故事板中使用此自定義視圖時(在Identity Inspector中將視圖更改爲我的視圖,除了那些從對象庫中提取的UIControls。 – tounaobun 2014-10-31 02:50:30

相關問題