Ios UIButton的自定义类视图
在Identity Inspector中,我想为我的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
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
}
}