Ich habe versucht, eine Sammlungsansicht zu erstellen, die Tags horizontal in zwei Zeilen darstellt. Der Benutzer kann dann horizontal scrollen, um weitere Tags anzuzeigen. Genau wie die Filter in der Bandcamp App https://itunes.apple.com/us/app/bandcamp/id706408639?mt=8Horizontaler Bildlauf UICollectionView zeigt Tags an (benutzerdefiniertes Layout)
Ich fand ein sehr gutes Tutorial, wie Sie etwas Ähnliches tun, indem Sie UICollectionViewFlowLayout anpassen. https://codentrick.com/create-a-tag-flow-layout-with-uicollectionview/
Dieses Lernprogramm ist jedoch für eine vertikale Sammlungsansicht gedacht, bei der Zeilen nach Bedarf erstellt werden. Was ich brauche ist, dass die Tags richtig fließen und das Layout auf zwei Zeilen beschränkt wird. Diese
ist das Snippet des UICollectionViewFlowLayout aus dem Tutorial
class FlowLayout: UICollectionViewFlowLayout {
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributesForElementsInRect = super.layoutAttributesForElementsInRect(rect)
var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]()
var leftMargin: CGFloat = 0.0;
for attributes in attributesForElementsInRect! {
if (attributes.frame.origin.x == self.sectionInset.left) {
leftMargin = self.sectionInset.left
} else {
var newLeftAlignedFrame = attributes.frame
newLeftAlignedFrame.origin.x = leftMargin
attributes.frame = newLeftAlignedFrame
}
leftMargin += attributes.frame.size.width + 8
newAttributesForElementsInRect.append(attributes)
}
return newAttributesForElementsInRect
}
}
Thx!
ich eine ähnliche Art von Problem haben, und ich brauche Hilfe http://stackoverflow.com/questions/38163448/issue-with-placing-cells-in- custom-flow-Layout von uicollectionviews – Ranjit