LoginSignup
0
0

More than 1 year has passed since last update.

xibでViewを作った

Last updated at Posted at 2021-07-14

xibでViewを作った

816CF66F-0EEF-43D4-B13C-B078EC3866CA_1_201_a.jpeg

機能説明

  • Buttonを押したら、Modalでxibファイルで作成したViewを表示させる

コード

  • Podfileには、pod 'FSCalendar'を入力
Podfile
 pod 'FSCalendar'

FSCalendar

  • FSCalendar()をインスタンス化➡️カレンダーのサイズなどの見た目を決める➡️addSubview(FSCalendarのインスタンス) 
FSCalendarModel
import Foundation
import FSCalendar

class FSCalendarModel:UIViewController{

    let fsCalendar = FSCalendar()

    func createCalemdar(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat, targetView:UIView){

        self.fsCalendar.frame = CGRect(x: x, y: y, width: width, height: height)

        targetView.addSubview(self.fsCalendar)

    }
}

View

B76C93F9-9335-4952-8562-DA0A9764C444_1_201_a.jpeg

ModalView
import Foundation
import UIKit

class ModalView:UIViewController{

    @IBOutlet weak var partsView: UIView!
    @IBOutlet weak var calendarView: UIView!

    let fsCalendarModel = FSCalendarModel()

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        self.partsView.layer.cornerRadius = 22.0
        self.calendarView.layer.cornerRadius = 22.0

        self.fsCalendarModel.createCalemdar(x: 0, y: 0, width: self.calendarView.frame.size.width, height: self.calendarView.frame.size.height, targetView: self.calendarView)     

    }
}

Controller

ViewController
import UIKit

class ViewController: UIViewController, UIViewControllerTransitioningDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func show(_ sender: Any) {

        let modalView = ModalView()
        modalView.modalPresentationStyle = .automatic
        modalView.transitioningDelegate = self
        present(modalView, animated: true, completion: nil)

    }

}

終わり

素敵なUI作りたい
ただ、コードを載せただけになってる気がする

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0