Greg's ButtonFun

ButtonFun
=========

In this branch, I developed the app to the spec of the [README](../blob/GregsBranch/README.md), with some additional features. The app is Universal, working on both ipad and iPhone, lays itself out intelligently in all orientations, and uses 0 UIButtons :). Most of the classes are self documented in their respective header files.

To display the grid, I utilized a UICollectionView and a custom UICollectionViewFlowLayout. See [CompactCollectionViewController.h] (../blob/GregsBranch/ButtonFun/ButtonFun/CompactCollectionViewController.h) and [CompactFlowLayout.h](../blob/GregsBranch/ButtonFun/ButtonFun/CompactFlowLayout.h) respectively. As we discussed, when items do not fill the screen completely, the layout absorbs the extra space equally on opposite sides. This has the effect of centering the grid along the axis/axes that have extra space.

![ios simulator screen shot oct 26 2014 1 29 19 pm](https://cloud.githubusercontent.com/assets/1018158/4783780/b1d1d844-5d35-11e4-9305-ac2816065d44.png)


The layout by default uses 0 spacing between items. Implementers are free to adjust these values and can therefore produce drastically different layouts, all while keeping it compact. See discussion on ```minimumInteritemSpacing ``` and ```minimumLineSpacing ``` in [CompactFlowLayout.h](../blob/GregsBranch/ButtonFun/ButtonFun/CompactFlowLayout.h).

10px spacing between items:
![ios simulator screen shot oct 26 2014 1 31 02 pm](https://cloud.githubusercontent.com/assets/1018158/4783790/f5eb16c6-5d35-11e4-8a90-429c97fdd74d.png)

20px spacing between horizontal items with 50px between vertical items:
![ios simulator screen shot oct 26 2014 1 34 45 pm](https://cloud.githubusercontent.com/assets/1018158/4783803/86127a28-5d36-11e4-8028-23b2acec4d9c.png)

 Additionally, there is no constraint that an item must be square. Implementers can provide any CGSize they wish. See ```itemSize``` in [CompactCollectionViewController.h](../blob/GregsBranch/ButtonFun/ButtonFun/CompactCollectionViewController.h).

Items of size (20,60) with 0 spacing in landscape mode:
![ios simulator screen shot oct 26 2014 1 37 41 pm](https://cloud.githubusercontent.com/assets/1018158/4783813/f396f560-5d36-11e4-83ba-0415fa9b2df9.png)

 By subclassing ```MainViewController``` and overriding ```collectionView:cellForItemAtIndexPath: ```, implementers can also control the shape of their buttons. For example a subclass of MainViewController using this code:
```
 -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell * cell = [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
    cell.layer.cornerRadius = cell.frame.size.height / 2;
    cell.layer.masksToBounds = YES;
    
    return cell;
} 
```
would create a grid of circular buttons:
![ios simulator screen shot oct 26 2014 2 49 25 pm](https://cloud.githubusercontent.com/assets/1018158/4784046/70f1f866-5d41-11e4-8c34-ef7dc0c26ed7.png)

When each item is laid out, it's background color is set to a random color. Implementers have the option of providing custom colors, or they can use the default list. When a button is selected (an item in the collectionView is selected), it's background color is animated to a new random color. Additionally, on selection, the statistics of each color of button are recorded into CoreData. See [Store.h](../blob/GregsBranch/ButtonFun/ButtonFun/Store.h). For example, if the user tapped on 2 green, 1 red, and 1 blue button the database would look something like this:

| StatisticMO | Color | Count  |
| --------------- |:--------:| --------:|
| 0 | Green | 2 |
| 1 | Red     |  1 |
| 2 | Blue    |  1 |

#### Statistics view
A long press on the view pushes a modal viewcontroller that shows the Statistics currently recorded in CoreData. The user has the option to reset the recorded statistics at this screen and can return back to the grid. See  [StatisticsViewController.h](../blob/GregsBranch/ButtonFun/ButtonFun/StatisticsViewController.h).

![ios simulator screen shot oct 26 2014 1 44 01 pm](https://cloud.githubusercontent.com/assets/1018158/4783837/ceaa77da-5d37-11e4-8838-8d6d8cdd3eea.png)