Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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 UIButton的自定义类视图_Ios_Objective C_Iphone_Uiview_Uibutton - Fatal编程技术网

Ios UIButton的自定义类视图

Ios UIButton的自定义类视图,ios,objective-c,iphone,uiview,uibutton,Ios,Objective C,Iphone,Uiview,Uibutton,在Identity Inspector中,我想为我的UIButton设置一个自定义类。 因此,我创建了一个自定义类,它是一个UIView,但我的自定义类没有出现在列表中。 反之亦然,如果我添加一个ui视图,列表上会出现包含的大多数类ui按钮 如果UIButton是UIView的子类,而不是UIView是UIButton, 为什么可能,为什么不能使用我的UIView自定义类来表示我的UIButton?我不太清楚你的意思,但我可以试试 你的问题 如果UIButton是UIView的子类,而不是UIV

在Identity Inspector中,我想为我的
UIButton
设置一个自定义类。 因此,我创建了一个自定义类,它是一个
UIView
,但我的自定义类没有出现在列表中。 反之亦然,如果我添加一个
ui视图
,列表上会出现包含的大多数类
ui按钮

如果
UIButton
UIView
的子类,而不是
UIView
UIButton

为什么可能,为什么不能使用我的
UIView
自定义类来表示我的
UIButton

我不太清楚你的意思,但我可以试试

你的问题

如果UIButton是UIView的子类,而不是UIView是UIButton,那么说明为什么可能以及为什么不能使用UIView自定义类来表示UIButton

我相信你是在说

  • UIButton
    UIView
    的子类
  • 自定义视图是
    UIView
    的子类
  • 为什么不能将
    ui按钮设置为自定义视图
  • 是这样吗

    如果是这样,那就相当清楚了。仅仅因为它们来自同一个类并不意味着它们是相关的。
    ui标签
    也是从
    ui视图
    派生出来的,但非常不同

    如果要创建
    UIButton
    的自定义子类,则自定义类应派生自
    UIButton

    你应该

    @interface YourSubclass: UIButton
    
    而不是

    @interface YourSubclass: UIView
    
    这样做将使自定义子类出现在Interface Builder的Identity Inspector中

    可以为UIButton创建自定义子类。然后将其设置为任何按钮的自定义类


    我不建议对UIButton进行子类化,但如果您仍想这样做,请创建从UIButton继承的customClass,而不是UIView。然后它会出现在我理解的identity inspectorOk中,在UIView列表中我会显示UIButton,因为它是UIView的子类。很抱歉问这么简单的问题,我是新手
    class CCButton: UIButton {
    
        /*
        // Only override drawRect: if you perform custom drawing.
        // An empty implementation adversely affects performance during animation.
        override func drawRect(rect: CGRect) {
            // Drawing code
        }
        */
    
        required init(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)!
            createBorder()
        }
    
        required override init(frame: CGRect) {
            super.init(frame: frame)
            createBorder()
        }
    
        private func createBorder(){
            //Define Layer
            self.layer.cornerRadius  = 8.0
            self.layer.masksToBounds = true
        }
    }