1

I need help align a Subview in ContainerView. I tried to add contraints but it messed up everything so I tried FluentLayout (https://github.com/FluentLayout/Cirrious.FluentLayout)

My Code looks like this:

public override void ViewDidLoad()
        {

            SFCalendar calendar = new SFCalendar();
            containerView.AddSubview(calendar);

            containerView.AtBottomOf(this.View);
            containerView.AtTopOf(this.View);
            containerView.WithSameWidth(this.View);

            calendar.AtBottomOf(containerView);
            calendar.AtTopOf(containerView);
            calendar.WithSameWidth(containerView);
        }

But in the end my Calendar is cut off a bit, what i am doing wrong here?

enter image description here enter image description here

BR75
  • 633
  • 7
  • 25

2 Answers2

1

Before you use the Autolayout, you should disable the TranslatesAutoresizingMaskIntoConstraints. So set this two controls property to False will make a trick, moreover you should correct your usage:

containerView.TranslatesAutoresizingMaskIntoConstraints = false;

SFCalendar calendar = new SFCalendar();
containerView.AddSubview(calendar);

calendar.TranslatesAutoresizingMaskIntoConstraints = false;

View.AddConstraints(containerView.AtBottomOf(this.View),
containerView.AtTopOf(this.View),
containerView.WithSameWidth(this.View));


containerView.AddConstraints(calendar.AtBottomOf(containerView),
calendar.AtTopOf(containerView),
calendar.WithSameWidth(containerView));

But I recommend you to use the native Constraints to do this, also it seems you want to make this containerView full screen. Add its leading, trailing, top, bottom will be better:

SFCalendar calendar = new SFCalendar();
containerView.AddSubview(calendar);

containerView.TranslatesAutoresizingMaskIntoConstraints = false;
containerView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor).Active = true;
containerView.TopAnchor.ConstraintEqualTo(TopLayoutGuide.GetBottomAnchor()).Active = true;
containerView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor).Active = true;
containerView.BottomAnchor.ConstraintEqualTo(BottomLayoutGuide.GetTopAnchor()).Active = true;

calendar.TranslatesAutoresizingMaskIntoConstraints = false;
calendar.LeadingAnchor.ConstraintEqualTo(containerView.LeadingAnchor).Active = true;
calendar.TopAnchor.ConstraintEqualTo(containerView.TopAnchor).Active = true;
calendar.TrailingAnchor.ConstraintEqualTo(containerView.TrailingAnchor).Active = true;
calendar.BottomAnchor.ConstraintEqualTo(containerView.BottomAnchor).Active = true;
Ax1le
  • 6,563
  • 2
  • 14
  • 61
1

We have created a sample by using NSLayoutConstraint. In this you can the change the layout size, but we cannot access the fluentlayout in this. please find the sample from the following link

Ishank
  • 2,860
  • 32
  • 43
Vinnalan
  • 11
  • 1