ich glaube, Sie UICollectionViewFlowLayout
Unterklasse können, und überschreiben Methode -
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
#import <UIKit/UIKit.h>
@interface CustomViewFlowLayout : UICollectionViewFlowLayout
@property(nonatomic) CGFloat maximumLineSpacing;
@end
@implementation CustomlViewFlowLayout
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *answer = [super layoutAttributesForElementsInRect:rect];
for(int i = 1; i < answer.count; ++i) {
UICollectionViewLayoutAttributes *currentLayoutAttributes = answer[i];
UICollectionViewLayoutAttributes *prevLayoutAttributes = answer[i - 1];
NSInteger maximumSpacing = self.maximumLineSpacing;
NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame);
if(origin + maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize.width) {
CGRect frame = currentLayoutAttributes.frame;
frame.origin.x = origin + maximumSpacing;
currentLayoutAttributes.frame = frame;
}
if (currentLayoutAttributes.frame.origin.y != prevLayoutAttributes.frame.origin.y) {
CGRect frame = currentLayoutAttributes.frame;
frame.origin.x = 0;
currentLayoutAttributes.frame = frame;
}
}
return answer;
}
@end
Eigentum maximumLineSpacing
verwendet, um den maximalen Zeilenabstand einstellen