DatePicker in TableView Header

fjr_wlb_njfjr_wlb_nj Member ✭✭

Hello,

I'm trying to provide a custom "Day Events" Calendar in a Tableview. Is it possible to put a DatePicker in the TableView header?

Thanks in advance?

Best Answers

  • fjr_wlb_njfjr_wlb_nj ✭✭
    Accepted Answer

    For anyone else looking to do this, the answer is yes it is possible. Here is my code:

        /// <summary>
        /// Gets the view for header.
        /// </summary>
        /// <returns>The view for header.</returns>
        /// <param name="tableView">Table view.</param>
        /// <param name="section">Section.</param>
        public override UIView GetViewForHeader(UITableView tableView, nint section)
        {
            //  Create Container View
            UIView _viewForDatePicker = new UIView()
            {
                BackgroundColor = UIColor.Blue
    
            };
    
            //  Create DatePicker Here
            UIDatePicker _datePickerView = new UIDatePicker();
            _datePickerView.SetValueForKey(UIColor.White, new NSString("textColor"));
            _datePickerView.Mode = UIDatePickerMode.Date;
    
            //  Capture Frame to Resize
            CGRect frame = _datePickerView.Frame;
            frame.Width = 400;
            frame.Height = 125;
    
            // Set new Frame dimensions to DatePicker
            _datePickerView.Frame = frame;
    
            //  Some container clean-up
            _viewForDatePicker.ClipsToBounds = true;
            _viewForDatePicker.SizeToFit();
            _viewForDatePicker.AddSubview(_datePickerView);
    
            return _viewForDatePicker;
        }
    

Answers

  • fjr_wlb_njfjr_wlb_nj Member ✭✭
    Accepted Answer

    For anyone else looking to do this, the answer is yes it is possible. Here is my code:

        /// <summary>
        /// Gets the view for header.
        /// </summary>
        /// <returns>The view for header.</returns>
        /// <param name="tableView">Table view.</param>
        /// <param name="section">Section.</param>
        public override UIView GetViewForHeader(UITableView tableView, nint section)
        {
            //  Create Container View
            UIView _viewForDatePicker = new UIView()
            {
                BackgroundColor = UIColor.Blue
    
            };
    
            //  Create DatePicker Here
            UIDatePicker _datePickerView = new UIDatePicker();
            _datePickerView.SetValueForKey(UIColor.White, new NSString("textColor"));
            _datePickerView.Mode = UIDatePickerMode.Date;
    
            //  Capture Frame to Resize
            CGRect frame = _datePickerView.Frame;
            frame.Width = 400;
            frame.Height = 125;
    
            // Set new Frame dimensions to DatePicker
            _datePickerView.Frame = frame;
    
            //  Some container clean-up
            _viewForDatePicker.ClipsToBounds = true;
            _viewForDatePicker.SizeToFit();
            _viewForDatePicker.AddSubview(_datePickerView);
    
            return _viewForDatePicker;
        }
    
Sign In or Register to comment.