forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarBlackoutDates.cs
136 lines (116 loc) · 3.66 KB
/
CalendarBlackoutDates.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#region Copyright Syncfusion Inc. 2001-2022.
// Copyright Syncfusion Inc. 2001-2022. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Collections.Generic;
using Syncfusion.SfCalendar.iOS;
#if __UNIFIED__
using Foundation;
using UIKit;
using CoreGraphics;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using CGRect = System.Drawing.RectangleF;
using CGPoint = System.Drawing.PointF;
using CGSize = System.Drawing.SizeF;
using nfloat = System.Single;
using System.Drawing;
#endif
namespace SampleBrowser
{
public class CalendarBlackoutDates : SampleView
{
private SFCalendar calendar1;
private static UITableView appView;
private UIView calendarView = new UIView();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public CalendarBlackoutDates()
{
//Calendar
calendar1 = new SFCalendar();
calendar1.ViewMode = SFCalendarViewMode.SFCalendarViewModeMonth;
calendar1.HeaderHeight = 40;
this.AddSubview(calendar1);
//Setting BlackOutDates
NSDate today = new NSDate();
NSCalendar calendar = NSCalendar.CurrentCalendar;
// Get the year, month, day from the date
NSDateComponents components = calendar.Components(
NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
// Set the hour, minute, second
calendar1.BlackoutDates = new NSMutableArray();
for (int i = 0; i < 5; i++)
{
NSDate startDate = calendar.DateFromComponents(components);
components.Day += 1;
calendar1.BlackoutDates.Add(startDate);
}
appView = new UITableView();
appView.RegisterClassForCellReuse(typeof(UITableViewCell), "Cell");
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
calendarView.AddSubview(calendar1);
this.AddSubview(calendarView);
}
this.AddSubview(appView);
}
public override void LayoutSubviews()
{
foreach (var view in this.Subviews)
{
if (view is SFCalendar)
{
view.Frame = new CGRect(this.Frame.X, -2, Frame.Size.Width, Frame.Size.Height);
}
calendarView.Frame = new CGRect(0, 0, this.Frame.Size.Width, this.Frame.Size.Height);
calendar1.Frame = new CGRect(0, 0, this.Frame.Size.Width, this.Frame.Size.Height);
}
base.LayoutSubviews();
}
public class CalendarPickerModel : UIPickerViewModel
{
private readonly IList<string> values;
public event EventHandler<CalendarPickerChangedEventArgs> PickerChanged;
public CalendarPickerModel(IList<string> values)
{
this.values = values;
}
#if __UNIFIED__
public override nint GetComponentCount(UIPickerView picker)
{
return 1;
}
public override nint GetRowsInComponent(UIPickerView picker, nint component)
{
return values.Count;
}
public override string GetTitle(UIPickerView picker, nint row, nint component)
{
return values[(int)row];
}
public override nfloat GetRowHeight(UIPickerView picker, nint component)
{
return 30f;
}
public override void Selected(UIPickerView picker, nint row, nint component)
{
if (this.PickerChanged != null)
{
this.PickerChanged(this, new CalendarPickerChangedEventArgs { SelectedValue = values[(int)row] });
}
}
#else
#endif
}
public class CalendarPickerChangedEventArgs : EventArgs
{
public string SelectedValue { get; set; }
}
}
}