-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHorizontalList.m
More file actions
78 lines (62 loc) · 2.8 KB
/
HorizontalList.m
File metadata and controls
78 lines (62 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// HorizontalList.m
// instatext
//
// Created by Varun Jain on 12/03/13.
// Copyright (c) 2013 Varun Jain. All rights reserved.
//
#import "HorizontalList.h"
#import "MainCategoryItem.h"
@implementation HorizontalList
- (id)initWithFrame:(CGRect)frame items:(NSMutableArray *)items numberOfRows:(NSUInteger)rows
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"number of items %d", [items count]);
CGSize pageSize = CGSizeMake(ITEM_WIDTH, self.scrollView.frame.size.height);
NSLog(@"page size %f ", pageSize.width);
NSUInteger numberOfColumns = [items count] / rows;
NSUInteger colIndex = 0;
NSUInteger rowIndex = 0;
self.rows = rows;
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, TITLE_HEIGHT, ITEM_WIDTH * (numberOfColumns + 1), ITEM_HEIGHT * rows)];
for (colIndex = 0; colIndex < numberOfColumns; colIndex++) {
for (rowIndex = 0; rowIndex < rows; rowIndex++) {
MainCategoryItem *item = [items objectAtIndex: colIndex * rows + rowIndex];
[item setFrame:CGRectMake(LEFT_PADDING + (ITEM_WIDTH + DISTANCE_BETWEEN_ITEMS) * colIndex, ITEM_HEIGHT * rowIndex, ITEM_WIDTH, ITEM_HEIGHT)];
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemTapped:)];
[item addGestureRecognizer:singleFingerTap];
[self.scrollView addSubview:item];
}
}
/**
for (MainCategoryItem *item in items) {
[item setFrame:CGRectMake(LEFT_PADDING + (pageSize.width + DISTANCE_BETWEEN_ITEMS) * page++, 0, pageSize.width, pageSize.height)];
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemTapped:)];
[item addGestureRecognizer:singleFingerTap];
[self.scrollView addSubview:item];
}
**/
self.scrollView.contentSize = CGSizeMake( LEFT_PADDING + [items count] * (ITEM_WIDTH + DISTANCE_BETWEEN_ITEMS), pageSize.height);
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
[self addSubview:self.scrollView];
}
return self;
}
- (void) itemTapped: (UITapGestureRecognizer *)recognizer{
UIView *item = (UIView *)recognizer.view;
if (item != nil) {
[self.delegate didSelectItem: item];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end