Je crée une vue de collection avec plusieurs tailles d'étiquettes. Ces étiquettes ont toutes la même hauteur mais leurs largeurs sont changées dynamiquement.Aligné à gauche Cellule UICollectionView Lorsqu'il a un élément dans Xamarin.ios
C'est le code de mon point de vue collection mise en page:
EstimatedItemSize = new CGSize(50f, 35f);
MinimumInteritemSpacing = 10f;
MinimumLineSpacing = 10f;
public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
{
var attributes = base.LayoutAttributesForElementsInRect(rect);
for (var i = 1; i < attributes.Length; ++i)
{
var currentLayoutAttributes = attributes[i];
var previousLayoutAttributes = attributes[i - 1];
var maximumSpacing = MinimumInteritemSpacing;
var previousLayoutEndPoint = previousLayoutAttributes.Frame.Right;
if (previousLayoutEndPoint + maximumSpacing + currentLayoutAttributes.Frame.Size.Width >= CollectionViewContentSize.Width)
{
continue;
}
var frame = currentLayoutAttributes.Frame;
frame.X = previousLayoutEndPoint + maximumSpacing;
currentLayoutAttributes.Frame = frame;
}
return attributes;
}
Ma question est: Quand j'ai un élément dans ma collection voir est affichée au centre, et LayoutAttributesForElementsInRect
méthode ne sera pas appelé. Mais j'ai besoin de l'afficher sur le côté gauche.
Si je change EstimatedItemSize = new CGSize(50f, 35f)
en ItemSize = new CGSize(50f, 35f)
il s'affiche correctement, mais la largeur n'est pas modifiée dynamiquement.
Je poster une réponse. Ou vous pouvez utiliser une autre bibliothèque tierce comme ceci: https://github.com/mokagio/UICollectionViewLeftAlignedLayout. –