I'm using Swift
, and I find myself having to subclass UIKit
classes such as UIView
and UIButton
. I don't care about setting the frame since I'm using AutoLayout
, so I don't want/need to use init(frame: CGRect)
.
class customSubclass: UIView {
var logo: UIImage
init(logo: UIImage) {
self.logo = logo
//compiler yells at me since super.init() isn't called before return from initializer
//so I end up doing this
super.init(frame: CGRectZero)
self.translatesAutoresizingMaskIntoConstraints = false
}
I also don't find it very sexy to set it's frame to CGRectZero
.
Is there a way to having a custom initializer for a subclass of a UIView or UIButton without explicitly setting it's frame?
Note Every subclass is instantiated in code, so required init(coder: aDecoder)
is in my code, but isn't actually doing anything.
Thanks!