现实开发中可以自定义一个UIButton,可以通过重写父类的这两个方法来实现基本的subViews的frame
class menuButton: UIButton {
override func titleRect(forContentRect contentRect: CGRect) -> CGRect {
return CGRect(x: 0, y: contentRect.height*0.65, width: contentRect.width, height: contentRect.height*0.35)
}
override func imageRect(forContentRect contentRect: CGRect) -> CGRect {
return CGRect(x: 5, y: 18, width: contentRect.width-10, height: contentRect.height*0.65-23)
}
}
这样就定义了menuButton的subViews的frame,很实用,很简洁
本文介绍如何通过重写titleRect和imageRect方法来自定义UIButton的子视图布局,提供了一个具体的menuButton实例,展示了简洁而实用的自定义按钮设计。
2628

被折叠的 条评论
为什么被折叠?



