Beispiel #1
0
        private void Initialize()
        {
            m_internalBinding.DataContext = this;

            var rectanglePreview = new UIView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            m_internalBinding.SetBackgroundColorBinding(rectanglePreview, nameof(Color));
            AddSubview(rectanglePreview);
            rectanglePreview.StretchWidth(this);

            m_channelR = CreateChannelView("R", (float)Color.Components[0] * 255, new UIColor(200 / 255f, 0, 0, 1));
            m_channelG = CreateChannelView("G", (float)Color.Components[1] * 255, new UIColor(0, 200 / 255f, 0, 1));
            m_channelB = CreateChannelView("B", (float)Color.Components[2] * 255, new UIColor(0, 0, 200 / 255f, 1));

            AddSubview(m_channelR);
            AddSubview(m_channelG);
            AddSubview(m_channelB);
            m_channelR.StretchWidth(this, left: 16, right: 16);
            m_channelG.StretchWidth(this, left: 16, right: 16);
            m_channelB.StretchWidth(this, left: 16, right: 16);

            this.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[preview(>=130)]-8-[channelR]-8-[channelG]-8-[channelB]-8-|", NSLayoutFormatOptions.DirectionLeadingToTrailing,
                                                                    "preview", rectanglePreview,
                                                                    "channelR", m_channelR,
                                                                    "channelG", m_channelG,
                                                                    "channelB", m_channelB));
        }
Beispiel #2
0
        public UIScheduleItemView(ViewItemSchedule item)
        {
            Item = item;
            m_classBindingHost.BindingObject = item.Class;

            m_classBindingHost.SetBackgroundColorBinding(this, nameof(item.Class.Color));

            var minTextHeight = UIFont.PreferredCaption1.LineHeight;

            var labelClass = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor = UIColor.White,
                Lines     = 0,
                Font      = UIFont.PreferredCaption1
            };

            m_classBindingHost.SetLabelTextBinding(labelClass, nameof(item.Class.Name));
            this.Add(labelClass);
            labelClass.StretchWidth(this, left: 4);

            // Time and room don't need to be data bound, since these views will be re-created if those change
            var labelTime = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text      = PowerPlannerResources.GetStringTimeToTime(DateTimeFormatterExtension.Current.FormatAsShortTime(item.StartTime), DateTimeFormatterExtension.Current.FormatAsShortTime(item.EndTime)),
                TextColor = UIColor.White,
                Lines     = 1,
                Font      = UIFont.PreferredCaption1
            };

            this.Add(labelTime);
            labelTime.StretchWidth(this, left: 4);

            labelTime.SetContentCompressionResistancePriority(1000, UILayoutConstraintAxis.Vertical);

            if (string.IsNullOrWhiteSpace(item.Room))
            {
                this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-2-[labelClass(>={minTextHeight})][labelTime]->=2-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                            "labelClass", labelClass,
                                                                            "labelTime", labelTime)));
            }
            else
            {
                var labelRoom = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text      = item.Room.Trim(),
                    TextColor = UIColor.White,
                    Font      = UIFont.PreferredCaption1,
                    Lines     = 0
                };
                this.Add(labelRoom);
                labelRoom.StretchWidth(this, left: 4, right: 4);

                labelRoom.SetContentCompressionResistancePriority(900, UILayoutConstraintAxis.Vertical);

                this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-2-[labelClass(>={minTextHeight})][labelTime][labelRoom]->=2-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                            "labelClass", labelClass,
                                                                            "labelTime", labelTime,
                                                                            "labelRoom", labelRoom)));
            }
        }
        public UIScheduleItemView(ViewItemSchedule item)
        {
            Item = item;
            m_classBindingHost.BindingObject = item.Class;

            m_classBindingHost.SetBackgroundColorBinding(this, nameof(item.Class.Color));

            var minTextHeight = UIFont.PreferredCaption1.LineHeight;

            var labelClass = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor = UIColor.White,
                Lines     = 0,
                Font      = UIFont.PreferredCaption1
            };

            m_classBindingHost.SetLabelTextBinding(labelClass, nameof(item.Class.Name));
            this.Add(labelClass);
            labelClass.StretchWidth(this, left: 4);

            // Time and room don't need to be data bound, since these views will be re-created if those change
            var labelTime = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text      = PowerPlannerResources.GetStringTimeToTime(DateTimeFormatterExtension.Current.FormatAsShortTime(item.StartTime), DateTimeFormatterExtension.Current.FormatAsShortTime(item.EndTime)),
                TextColor = UIColor.White,
                Lines     = 1,
                Font      = UIFont.PreferredCaption1
            };

            this.Add(labelTime);
            labelTime.StretchWidth(this, left: 4);

            labelTime.SetContentCompressionResistancePriority(1000, UILayoutConstraintAxis.Vertical);

            if (string.IsNullOrWhiteSpace(item.Room))
            {
                this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-2-[labelClass(>={minTextHeight})][labelTime]->=2-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                            "labelClass", labelClass,
                                                                            "labelTime", labelTime)));
            }
            else
            {
                var textViewRoom = new UITextView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text      = item.Room.Trim(),
                    TextColor = UIColor.White,
                    //TintColor = UIColor.White, // Link color
                    WeakLinkTextAttributes = new NSDictionary(UIStringAttributeKey.ForegroundColor, UIColor.White, UIStringAttributeKey.UnderlineStyle, 1), // Underline links and make them white
                    BackgroundColor        = UIColor.Clear,
                    Font          = UIFont.PreferredCaption1,
                    Editable      = false,
                    ScrollEnabled = false,

                    // Link detection: http://iosdevelopertips.com/user-interface/creating-clickable-hyperlinks-from-a-url-phone-number-or-address.html
                    DataDetectorTypes = UIDataDetectorType.All
                };

                // Lose the padding: https://stackoverflow.com/questions/746670/how-to-lose-margin-padding-in-uitextview
                textViewRoom.TextContainerInset = UIEdgeInsets.Zero;
                textViewRoom.TextContainer.LineFragmentPadding = 0;

                this.Add(textViewRoom);
                textViewRoom.StretchWidth(this, left: 4, right: 4);

                textViewRoom.SetContentCompressionResistancePriority(900, UILayoutConstraintAxis.Vertical);

                this.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|-2-[labelClass(>={minTextHeight})][labelTime][labelRoom]->=2-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                            "labelClass", labelClass,
                                                                            "labelTime", labelTime,
                                                                            "labelRoom", textViewRoom)));
            }
        }