Articles in this section
Category / Section

How to include custom header using xib file in Xamarin.iOS Schedule?

1 min read

You can create custom header and add this in schedule. To achieve this, follow below steps.

 

  1. Set Schedule.HeaderHeight property as zero to hide the default header
  2. Create your own xib file and add your own custom view and schedule on it.

 

Including custom header in Xamarin Scheduler

 

C#

[Register ("MyViewCS")]
    partial class MyView
    {
        [Outlet]
        [GeneratedCode ("iOS Designer", "1.0")]
        UIKit.UILabel label { get; set; }
 
        [Outlet]
        [GeneratedCode ("iOS Designer", "1.0")]
        Syncfusion.SfSchedule.iOS.SFSchedule schedule { get; set; }
 
        void ReleaseDesignerOutlets ()
        {
            if (label != null) {
                label.Dispose ();
                label = null;
            }
 
            if (schedule != null) {
                schedule.Dispose ();
                schedule = null;
            }
        }
    }

 

  1. Add the created view in ViewController Class

C#

public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
 
            var view = MyView.Create();
            view.Frame = View.Frame;
 
            View.AddSubview(view);
        }

 

  1. Using Schedule.VisibleDatesChanged event get the visible month, and set this to custom header

 

C#

public static MyView Create()
        {
            var arguments = NSBundle.MainBundle.LoadNib("MyView", null, null);
            view = Runtime.GetNSObject<MyView>(arguments.ValueAt(0));
 
            view.schedule.HeaderHeight = 0;
 
            view.schedule.VisibleDatesChanged += Schedule_VisibleDatesChanged;
 
            view.label.BackgroundColor = UIColor.Blue;
 
            return view;
        }
 
        static void Schedule_VisibleDatesChanged(object sender, Syncfusion.SfSchedule.iOS.VisibleDatesChangedEventArgs e)
        {
            var dateList = e.VisibleDates;
 
            NSDateFormatter formatter = new NSDateFormatter();
            formatter.DateFormat = "LLLL YYYY";
            formatter.Locale = view.schedule.Locale;
 
            if (view.schedule.ScheduleView == SFScheduleView.SFScheduleViewMonth)
                view.label.Text = (NSString)formatter.ToString(dateList.GetItem<NSDate>(dateList.Count / 2));
            else
                view.label.Text = (NSString)formatter.ToString(dateList.GetItem<NSDate>(0));
        }

 

Example: ScheduleCustomHeader_iOS

 

Dates in Xamarin Scheduler

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied