Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UIView中自定义此图像选项卡,使用@IBDesignable和@IBInspectable更好_Ios_Swift_Uistoryboard - Fatal编程技术网

Ios 如何在UIView中自定义此图像选项卡,使用@IBDesignable和@IBInspectable更好

Ios 如何在UIView中自定义此图像选项卡,使用@IBDesignable和@IBInspectable更好,ios,swift,uistoryboard,Ios,Swift,Uistoryboard,如何在UIView中绘制以下选项卡图像?文本是可变的,这意味着图像可以拉伸宽度。我知道在XCode6中,它支持实时渲染。所以我认为如果可能的话,它的颜色、文本和大小可以在属性检查器中设置 您必须基于UIView创建一个自定义类。此类声明为@IBDesignable,并具有@IBInspectable属性。重写UIView.drawRect(),您就可以完全自由地查看视图的显示方式 下面是一个示例类,让您开始学习 import UIKit @IBDesignable class MyTabVie

如何在UIView中绘制以下选项卡图像?文本是可变的,这意味着图像可以拉伸宽度。我知道在XCode6中,它支持实时渲染。所以我认为如果可能的话,它的颜色、文本和大小可以在属性检查器中设置


您必须基于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
    }
}

还有一个问题,我为该自定义视图添加了相应的xib,并且在序列图像板中使用该自定义视图时,我向该xib中添加了一些uicontrol(在Identity Inspector中将类更改为我的视图,只有我编写的代码在序列图像板中渲染,但我从对象库中提取的uicontrol除外)。