実現したいこと
StoryboardでAutolayoutを組んだオリジナルの Alert View が表示されるようにしたいです。
Autolayoutを組まなければ完璧に表示できるのですがAutolayoutを組むと何も表示されなくなってしまいます。
どのようにすれば表示できますでしょうか?
AutoLayoutを全てコードで書くという方法があると思うのですが、今までstoryboardで書かれているプロジェクトなのでそちらに統一する必要がある状況で困っております。皆様のお力添えいただけますと幸いです。
ソースコード
swift
1import Foundation 2import UIKit 3 4class CustomAlertView: UIView { 5 6 @IBOutlet private weak var alertText: UILabel! 7 @IBOutlet private weak var cancelButton: UIButton! 8 @IBOutlet private weak var startButton: UIButton! 9 @IBOutlet private weak var scheduleButton: UIButton! 10 @IBOutlet private weak var containerView: UIView! 11 12 func loadNib() { 13 let view = Bundle.main.loadNibNamed("CustomAlertView", owner: self, options: nil)?.first as! UIView 14 15 containerView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5) 16 alertText.backgroundColor = UIColor(red: 255/255, green: 165/255, blue: 148/255, alpha: 1) 17 18 view.frame = self.bounds 19 self.addSubview(view) 20 21 } 22}
以下のViewControllerのbuttonPressedが作動されたらCustome Alert Viewが表示されるよう実装しています。
Swift
1@IBAction private func buttonPressed(_ sender: Any) { 2 3 //CustomViewを出す 4 let customAlertView = CustomAlertView() 5 view.isUserInteractionEnabled = false 6 view.addSubview(customAlertView) 7 8}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。