Dave Haigh
Dave Haigh

Reputation: 4547

How to utilise Constraints - FluentConstraints and FluentLayouts for Xamarin.iOS

I have a collection view in iOS that has been generated programmatically i.e. it doesn't have a nib. It is then being injected into a view on a page. I am using Xamarin Studio and MVVM Cross. When I run the app the collection is generated and injected in the right position. But as I scroll down and the scrollbar hits the bottom of the collection view it carries on scrolling but the scroll bar goes off the bottom of the screen.

I'm thinking the collection view isn't adhering the dimensions of the view im injecting it into so its height is too high. Can I set the height of the collection in code?

EDIT

Ok as im using MVVM I have found a way of achieving what I have explained in my question.

I have managed to get my collection view to adhere to the top and bottom of the view it is injected into. I have done this by using the Cirrious library Cirrious.FluentLayouts.Touch great post on here from Stuart Lodge http://slodge.blogspot.co.uk/2013/07/playing-with-constraints.html. With this I have eradicated the need to specify a height on the collection view and instead told it to stick to the top and bottom of the parent view.

e.g.

//Add constraints between collection view and its container in page
parentView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
parentView.AddConstraints(
  collectionsView.AtTopOf(parentView,0),
  collectionsView.AtBottomOf(parentView,0),
  collectionsView.AtLeftOf(parentView,0),
  collectionsView.AtRightOf(parentView,0)
);

Upvotes: 0

Views: 2599

Answers (2)

Trong Tran
Trong Tran

Reputation: 686

See some my demonstrations about auto layout on FluentLayout

https://www.evernote.com/l/AJPLFfvOaXVLxZNme8s9_PjjaazwRP-Bl9Y

Regards, Trong.

Upvotes: 1

Dave Haigh
Dave Haigh

Reputation: 4547

Ok as im using MVVM I have found a way of achieving what I have explained in my question.

I have managed to get my collection view to adhere to the top and bottom of the view it is injected into. I have done this by using the Cirrious library Cirrious.FluentLayouts.Touch great post on here from Stuart Lodge http://slodge.blogspot.co.uk/2013/07/playing-with-constraints.html. With this I have eradicated the need to specify a height on the collection view and instead told it to stick to the top and bottom of the parent view.

e.g.

//Add constraints between collection view and its container in page
parentView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
parentView.AddConstraints(
  collectionsView.AtTopOf(parentView,0),
  collectionsView.AtBottomOf(parentView,0),
  collectionsView.AtLeftOf(parentView,0),
  collectionsView.AtRightOf(parentView,0)
);

N.b. If you are working with elements that already exist within a nib file (.xib), then you may need to add the following line before adding your constraints if the constraints you are trying to add start to conflict.

parentView.removeConstraints(constraints: parentView.Constraints)

Upvotes: 2

Related Questions