mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Overall examples improvement
This commit is contained in:
@@ -34,34 +34,21 @@ static NSUInteger kNumberOfImages = 14;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
_sections = [NSMutableArray array];
|
||||
[_sections addObject:[NSMutableArray array]];
|
||||
for (NSUInteger idx = 0, section = 0; idx < kNumberOfImages; idx++) {
|
||||
NSString *name = [NSString stringWithFormat:@"image_%lu.jpg", (unsigned long)idx];
|
||||
[_sections[section] addObject:[UIImage imageNamed:name]];
|
||||
if ((idx + 1) % 5 == 0 && idx < kNumberOfImages - 1) {
|
||||
section++;
|
||||
[_sections addObject:[NSMutableArray array]];
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
_sections = [NSMutableArray array];
|
||||
[_sections addObject:[NSMutableArray array]];
|
||||
for (NSUInteger idx = 0, section = 0; idx < kNumberOfImages; idx++) {
|
||||
NSString *name = [NSString stringWithFormat:@"image_%lu.jpg", (unsigned long)idx];
|
||||
[_sections[section] addObject:[UIImage imageNamed:name]];
|
||||
if ((idx + 1) % 5 == 0 && idx < kNumberOfImages - 1) {
|
||||
section++;
|
||||
[_sections addObject:[NSMutableArray array]];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MosaicCollectionViewLayout *layout = [[MosaicCollectionViewLayout alloc] init];
|
||||
layout.numberOfColumns = 2;
|
||||
layout.headerHeight = 44.0;
|
||||
|
||||
_layoutInspector = [[MosaicCollectionViewLayoutInspector alloc] init];
|
||||
|
||||
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout asyncDataFetching:YES];
|
||||
_collectionView.asyncDataSource = self;
|
||||
_collectionView.asyncDelegate = self;
|
||||
_collectionView.layoutInspector = _layoutInspector;
|
||||
_collectionView.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -69,12 +56,27 @@ static NSUInteger kNumberOfImages = 14;
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
MosaicCollectionViewLayout *layout = [[MosaicCollectionViewLayout alloc] init];
|
||||
layout.numberOfColumns = 2;
|
||||
layout.headerHeight = 44.0;
|
||||
|
||||
_layoutInspector = [[MosaicCollectionViewLayoutInspector alloc] init];
|
||||
|
||||
_collectionView = [[ASCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
|
||||
_collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
|
||||
_collectionView.asyncDataSource = self;
|
||||
_collectionView.asyncDelegate = self;
|
||||
_collectionView.layoutInspector = _layoutInspector;
|
||||
_collectionView.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
||||
[self.view addSubview:_collectionView];
|
||||
}
|
||||
|
||||
- (void)viewWillLayoutSubviews
|
||||
- (void)dealloc
|
||||
{
|
||||
_collectionView.frame = self.view.bounds;
|
||||
_collectionView.asyncDataSource = nil;
|
||||
_collectionView.asyncDelegate = nil;
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden
|
||||
@@ -109,11 +111,13 @@ static NSUInteger kNumberOfImages = 14;
|
||||
return [[SupplementaryNode alloc] initWithText:text];
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||||
{
|
||||
return _sections.count;
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return [_sections[section] count];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user