gpt4 book ai didi

ios - MBCalanderKit 添加日历作为 subview

转载 作者:行者123 更新时间:2023-11-30 12:48:52 27 4
gpt4 key购买 nike

在我的应用程序中,我想要类似 iOS 日历应用程序的东西,所以我使用 MBCalanderKit 库。在我的应用程序中,我不想使用 CKCalendarViewController,因为我需要将日历添加为 subview 。

为此,我正在使用以下代码。我正在使用 xCode 7 和 swift 2.3

import MBCalendarKit

class ViewController: UIViewController {

var calanderView : CKCalendarView!

var data = [NSDate : AnyObject]()
override func viewDidLoad() {
super.viewDidLoad()

loadData()

calanderView = CKCalendarView(frame: self.view.frame)
calanderView.autoresizingMask = [.FlexibleWidth,.FlexibleHeight]

calanderView.delegate = self
calanderView.dataSource = self


self.view.addSubview(calanderView)

}

func loadData(){
let date = NSDate(day: 12, month: 12, year: 2016)
let event1 = CKCalendarEvent(title: "Birthday Event", andDate: date, andInfo: nil, andColor: UIColor.redColor())

let date2 = NSDate(day: 15, month: 12, year: 2016)
let event2 = CKCalendarEvent(title: "Party Event", andDate: date2, andInfo: nil, andColor: UIColor.redColor())

let date3 = NSDate(day: 17, month: 12, year: 2016)
let event3 = CKCalendarEvent(title: "Marriage Event", andDate: date3, andInfo: nil, andColor: UIColor.redColor())

let date4 = NSDate(day: 20, month: 12, year: 2016)
let event4 = CKCalendarEvent(title: "Splecal Event", andDate: date4, andInfo: nil, andColor: UIColor.redColor())

let date5 = NSDate(day: 25, month: 12, year: 2016)
let event5 = CKCalendarEvent(title: "Special Event", andDate: date5, andInfo: nil, andColor: UIColor.redColor())


data[date] = [event1]
data[date2] = [event2]
data[date3] = [event3]
data[date4] = [event4]
data[date5] = [event5]

}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

extension ViewController : CKCalendarViewDataSource{
func calendarView(calendarView: CKCalendarView!, eventsForDate date: NSDate!) -> [AnyObject]! {
if let dt = date{
if data[dt] != nil{
return [self.data[dt]!]
}
}
return nil
}
}
extension ViewController : CKCalendarViewDelegate{

}

但我的问题是,当我运行此代码时,我没有得到所需的输出。这是我的屏幕截图

enter image description here

请帮助我。

最佳答案

我也遇到了同样的问题只需将 View Controller 嵌入到导航 Controller 中,并在 View Controller View 顶部添加 UIView 为 UIView 建立一个导出

@IBOutlet var yourAddedView: UIView!

var 日历 = CKCalendarView()

覆盖 func viewDidLoad() {

    super.viewDidLoad()

calendar?.dataSource = self
calendar?.delegate = self

self.yourAddedView.addSubview(日历!)

}

关于ios - MBCalanderKit 添加日历作为 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41263954/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com