forked from Grouper/FlatUIKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIconViewController.m
More file actions
84 lines (69 loc) · 3.24 KB
/
IconViewController.m
File metadata and controls
84 lines (69 loc) · 3.24 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
79
80
81
82
83
84
//
// IconViewController.m
// FlatUIKitExample
//
// Created by Jamie Matthews on 12/24/14.
//
//
#import "IconViewController.h"
#import "FlatUIKit.h"
#import "NSString+Icons.h"
@implementation IconViewController{
UICollectionView *_collectionView;
NSArray *unicodeStrings;
NSArray *colorArray;
}
-(void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor = [UIColor cloudsColor];
self.title = @"Icons";
self.navigationController.navigationBar.translucent = NO;
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
_collectionView=[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
[_collectionView setDataSource:self];
[_collectionView setDelegate:self];
[_collectionView setTranslatesAutoresizingMaskIntoConstraints:NO];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
[_collectionView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:_collectionView];
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-0-[_collectionView]-0-|"
options:NSLayoutFormatDirectionLeadingToTrailing
metrics:nil
views:NSDictionaryOfVariableBindings(_collectionView)]];
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:|-0-[_collectionView]-0-|"
options:NSLayoutFormatDirectionLeadingToTrailing
metrics:nil
views:NSDictionaryOfVariableBindings(_collectionView)]];
// loop over all of the icon string values
unicodeStrings = [NSString iconUnicodeStrings];
// use a few different colors to show how these icons can be styled
colorArray = @[[UIColor turquoiseColor], [UIColor emerlandColor], [UIColor peterRiverColor], [UIColor amethystColor], [UIColor sunflowerColor], [UIColor carrotColor], [UIColor alizarinColor]];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [unicodeStrings count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
if(!cell){
}
else{
[[cell.contentView viewWithTag:100] removeFromSuperview];
}
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height)];
title.font = [UIFont iconFontWithSize:16];
title.textAlignment = NSTextAlignmentCenter;
title.text = [unicodeStrings objectAtIndex:indexPath.row];
title.tag = 100;
title.textColor = [colorArray objectAtIndex:indexPath.row%[colorArray count]];
[cell.contentView addSubview:title];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(50, 50);
}
@end