私はUIButton
のサブクラスをストーリーボードから初期化します。私はXibを使用していません。プログラムでUIActivityIndicatorView
を追加したいと思います。私のコードは次のとおりです。インポートUIKitUIButtonサブクラスにUIActivityIndicatorViewを追加できません
class ResendConfirmButton: UIButton {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
configActivityIndicator()
}
override func layoutSubviews() {
super.layoutSubviews()
configStyling()
}
func configStyling() {
let buttonLayer = CAShapeLayer()
let buttonPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: [UIRectCorner.bottomLeft, UIRectCorner.bottomRight], cornerRadii: CGSize(width: 2.0, height: 2.0))
buttonLayer.path = buttonPath.cgPath
buttonLayer.frame = bounds
layer.mask = buttonLayer
}
var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .white)
func configActivityIndicator() {
activityIndicator.center = CGPoint(x: bounds.midX, y: bounds.midY)
addSubview(activityIndicator)
activityIndicator.startAnimating()
}
}
しかし、何らかの理由でアクティビティインジケータが追加されていません。私はconfigActivityIndicator
をlayoutSubviews
に移動しようとしましたが、これも機能しません。このメソッドを呼び出すための適切な場所はどこですか?レイアウトサブビューコードで