private void InitializeUi() { // Holds all the views var viewHolder = new UIView { TranslatesAutoresizingMaskIntoConstraints = false }; Add(viewHolder); // Track Thumbnail _imageControl = new MvxCachedImageView { TranslatesAutoresizingMaskIntoConstraints = false, ContentMode = UIViewContentMode.ScaleAspectFill }; _imageControl.Layer.MasksToBounds = true; _imageControl.Layer.CornerRadius = _imageCornerRadius; var shadowView = new UIView { TranslatesAutoresizingMaskIntoConstraints = false }; shadowView.Layer.ShadowOpacity = 0.6f; shadowView.Layer.ShadowColor = UIColor.Black.CGColor; shadowView.Layer.ShadowRadius = 4.0f; shadowView.Layer.ShadowOffset = new CGSize(0, 3); shadowView.AddSubview(_imageControl); viewHolder.Add(shadowView); shadowView.LeftAnchor.ConstraintEqualTo(viewHolder.LeftAnchor, 4).Active = true; shadowView.TopAnchor.ConstraintEqualTo(viewHolder.TopAnchor, 4).Active = true; shadowView.HeightAnchor.ConstraintEqualTo(160).Active = true; shadowView.WidthAnchor.ConstraintEqualTo(160).Active = true; _imageControl.HeightAnchor.ConstraintEqualTo(160).Active = true; _imageControl.WidthAnchor.ConstraintEqualTo(160).Active = true; _imageControl.LeftAnchor.ConstraintEqualTo(shadowView.LeftAnchor).Active = true; _imageControl.TopAnchor.ConstraintEqualTo(shadowView.TopAnchor).Active = true; // Right Footer _rightFooter = new UILabel { TextColor = UIColor.White, TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.SystemFontOfSize(12f, UIFontWeight.Semibold) }; _imageControl.Add(_rightFooter); // Position the right footer _rightFooter.RightAnchor.ConstraintEqualTo(_imageControl.RightAnchor, -8).Active = true; _rightFooter.BottomAnchor.ConstraintEqualTo(_imageControl.BottomAnchor, -6).Active = true; // Left Footer _leftFooter = new UILabel { TextColor = UIColor.White, TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.FromName("FontAwesome5Pro-Light", 12) }; _imageControl.Add(_leftFooter); // Position the left footer _leftFooter.LeftAnchor.ConstraintEqualTo(_imageControl.LeftAnchor, 8).Active = true; _leftFooter.BottomAnchor.ConstraintEqualTo(_imageControl.BottomAnchor, -6).Active = true; // Title _title = new UILabel { TextColor = ColorHelper.Text0.ToPlatformColor(), TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.SystemFontOfSize(14f, UIFontWeight.Semibold), }; viewHolder.Add(_title); _title.LeftAnchor.ConstraintEqualTo(viewHolder.LeftAnchor, 6).Active = true; _title.TopAnchor.ConstraintEqualTo(viewHolder.TopAnchor, 174).Active = true; _title.WidthAnchor.ConstraintEqualTo(160).Active = true; // Subtitle _subtitle = new UILabel { TextColor = ColorHelper.Text0.ToPlatformColor(), TranslatesAutoresizingMaskIntoConstraints = false, Alpha = 0.8f, Font = UIFont.SystemFontOfSize(13f, UIFontWeight.Medium) }; viewHolder.Add(_subtitle); _subtitle.LeftAnchor.ConstraintEqualTo(viewHolder.LeftAnchor, 6).Active = true; _subtitle.TopAnchor.ConstraintEqualTo(viewHolder.TopAnchor, 194).Active = true; _subtitle.WidthAnchor.ConstraintEqualTo(160).Active = true; // The controller used for extra info _alertController = UIAlertController.Create("", "", UIAlertControllerStyle.ActionSheet); // Add the default close _alertController.AddAction(UIAlertAction.Create("Close", UIAlertActionStyle.Cancel, _ => _alertController.DismissViewController(true, null))); var gr = new UILongPressGestureRecognizer(); gr.AddTarget(() => LongPressed(gr)); AddGestureRecognizer(gr); }
private void InitializeUi() { // Root View with the shadow var rootView = new UIView { TranslatesAutoresizingMaskIntoConstraints = false }; Add(rootView); // Root view constraints rootView.HeightAnchor.ConstraintEqualTo(CellHeight).Active = true; rootView.LeftAnchor.ConstraintEqualTo(LeftAnchor, 18).Active = true; rootView.TopAnchor.ConstraintEqualTo(TopAnchor).Active = true; rootView.RightAnchor.ConstraintEqualTo(RightAnchor, -18).Active = true; // Thumbnail _imageControl = new MvxCachedImageView { TranslatesAutoresizingMaskIntoConstraints = false, ContentMode = UIViewContentMode.ScaleAspectFill }; _imageControl.Layer.MasksToBounds = true; _imageControl.Layer.CornerRadius = 6.0f; var shadowView = new UIView { TranslatesAutoresizingMaskIntoConstraints = false }; shadowView.Layer.ShadowOpacity = 0.6f; shadowView.Layer.ShadowColor = UIColor.Black.CGColor; shadowView.Layer.ShadowRadius = 4.0f; shadowView.Layer.ShadowOffset = new CGSize(0, 3); shadowView.AddSubview(_imageControl); rootView.Add(shadowView); shadowView.HeightAnchor.ConstraintEqualTo(CellHeight - 18).Active = true; shadowView.WidthAnchor.ConstraintEqualTo(CellHeight - 18).Active = true; shadowView.LeftAnchor.ConstraintEqualTo(rootView.LeftAnchor).Active = true; shadowView.TopAnchor.ConstraintEqualTo(rootView.TopAnchor, 18).Active = true; // Make sure the image is correctly sized _imageControl.HeightAnchor.ConstraintEqualTo(shadowView.HeightAnchor).Active = true; _imageControl.WidthAnchor.ConstraintEqualTo(shadowView.WidthAnchor).Active = true; _imageControl.LeftAnchor.ConstraintEqualTo(shadowView.LeftAnchor).Active = true; _imageControl.TopAnchor.ConstraintEqualTo(shadowView.TopAnchor).Active = true; // Right Footer _rightFooter = new UILabel { TextColor = UIColor.White, TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.SystemFontOfSize(11, UIFontWeight.Semibold) }; _imageControl.Add(_rightFooter); // Position the right footer _rightFooter.RightAnchor.ConstraintEqualTo(_imageControl.RightAnchor, -6).Active = true; _rightFooter.BottomAnchor.ConstraintEqualTo(_imageControl.BottomAnchor, -4).Active = true; // Left Footer _leftFooter = new UILabel { TextColor = UIColor.White, TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.FromName("FontAwesome5Pro-Light", 11) }; _imageControl.Add(_leftFooter); // Position the left footer _leftFooter.LeftAnchor.ConstraintEqualTo(_imageControl.LeftAnchor, 8).Active = true; _leftFooter.BottomAnchor.ConstraintEqualTo(_imageControl.BottomAnchor, -6).Active = true; // Title _title = new UILabel { TextColor = ColorHelper.Text0.ToPlatformColor(), TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.SystemFontOfSize(16f, UIFontWeight.Bold), LineBreakMode = UILineBreakMode.TailTruncation, Lines = 1, }; rootView.Add(_title); _title.LeftAnchor.ConstraintEqualTo(shadowView.RightAnchor, 12).Active = true; _title.RightAnchor.ConstraintEqualTo(rootView.RightAnchor).Active = true; _title.TopAnchor.ConstraintEqualTo(rootView.TopAnchor, 34).Active = true; // Ensure the label is fully set _title.PreferredMaxLayoutWidth = _title.Frame.Size.Width; _title.SizeToFit(); // Subtitle _subtitle = new UILabel { TextColor = ColorHelper.Text0.ToPlatformColor(), TranslatesAutoresizingMaskIntoConstraints = false, Alpha = 0.7f, Font = UIFont.SystemFontOfSize(15f, UIFontWeight.Regular), LineBreakMode = UILineBreakMode.TailTruncation, Lines = 1, }; rootView.Add(_subtitle); _subtitle.LeftAnchor.ConstraintEqualTo(shadowView.RightAnchor, 12).Active = true; _subtitle.RightAnchor.ConstraintEqualTo(rootView.RightAnchor).Active = true; _subtitle.TopAnchor.ConstraintEqualTo(_title.BottomAnchor, 4).Active = true; // Ensure the label is fully set _subtitle.PreferredMaxLayoutWidth = _subtitle.Frame.Size.Width; _subtitle.SizeToFit(); }