现实开发中可以自定义一个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,很实用,很简洁