PageRenderTime 134ms CodeModel.GetById 21ms RepoModel.GetById 8ms app.codeStats 0ms

Markdown | 115 lines | 83 code | 32 blank | 0 comment | 0 complexity | d82c5051f1a3e0c06679fb49d3668b22 MD5 | raw file
  1. # GSKStretchyHeaderView, by [gskbyte](
  2. [![License](](
  3. [![Platform](](
  4. [![Carthage compatible](](
  5. [![Version](](
  6. [![CI Status](](
  7. [![Coverage](](
  8. ![Example 1](
  9. ![Example 2](
  10. ![Example 3](
  11. ![Example 4](
  12. ![Example 5](
  13. GSKStretchyHeaderView is an implementation of the stretchy header paradigm as seen on many apps, like Twitter, Spotify or airbnb. It's designed in order to accomplish the following requirements:
  14. - Compatibility with `UITableView` and `UICollectionView`
  15. - Data source and delegate independency: can be added to an existing view controller withouth interfering with your existing `delegate` or `dataSource`
  16. - Provide support for frame layout, auto layout and Interface Builder `.xib` files
  17. - No need to subclass a custom view controller or to use a custom `UICollectionViewLayout`
  18. - Simple usage: just implement your own subclass and add it to your `UIScrollView` subclass
  19. - Two expansion modes: the header view can grow only when the top of the scroll view is reached, or as soon as the user scrolls down.
  20. If you are using this library in your project, I would be more than glad to [know about it!](
  21. ## Usage
  22. To add a stretchy header to your table or collection view, you just have to do this:
  23. ```objc
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. CGSize headerSize = CGSizeMake(self.tableView.frame.size.width, 200); // 200 will be the default height
  27. self.stretchyHeader = [[GSKStretchyHeaderViewSubclass alloc] initWithFrame:CGRectMake(0, 0, headerSize.width, headerSize.height)];
  28. self.stretchyHeader.delegate = self; // this is completely optional
  29. [self.tableView addSubview:self.stretchyHeader];
  30. }
  31. ```
  32. or
  33. ```objc
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. NSArray<UIView *> *nibViews = [[NSBundle mainBundle] loadNibNamed:@"GSKTabsStretchyHeaderView"
  37. owner:self
  38. options:nil];
  39. self.stretchyHeaderView = nibViews.firstObject;
  40. [self.tableView addSubview:self.stretchyHeaderView];
  41. }
  42. ```
  43. ## Configuration
  44. You can change multiple parameters in your stretchy header view:
  45. ```objc
  46. // you can change wether it expands at the top or as soon as you scroll down
  47. headerView.expansionMode = GSKStretchyHeaderViewExpansionModeImmediate;
  48. // You can change the minimum and maximum content heights
  49. headerView.minimumContentHeight = 64; // you can replace the navigation bar with a stretchy header view
  50. headerView.maximumContentHeight = 280;
  51. // You can specify if the content expands when the table view bounces, and if it shrinks if contentView.height < maximumContentHeight. This is specially convenient if you use auto layout inside the stretchy header view
  52. headerView.contentShrinks = YES;
  53. headerView.contentExpands = NO; // useful if you want to display the refreshControl below the header view
  54. // You can specify wether the content view sticks to the top or the bottom of the header view if one of the previous properties is set to NO
  55. // In this case, when the user bounces the scrollView, the content will keep its height and will stick to the bottom of the header view
  56. headerView.contentAnchor = GSKStretchyHeaderViewContentAnchorBottom;
  57. ```
  58. ## Creating your stretchy header
  59. There are two ways to create your own stretchy header:
  60. - Create a stretchy header subclass and add subviews to its `contentView`. You can layout its subviews manipulating their frames or using Auto Layout (also works with [GranadaLayout]( :trollface:).
  61. - Create an Interface Builder file and map it to your `GSKStretchyHeaderView` subclass. Subviews added to the stretchy header will be automatically moved to the content view, keeping their constraints. Remember to set the properties `maximumContentHeight` and `minimumContentHeight` in the attributes inspector (fourth tab on the right panel in Interface Builder).
  62. To modify the behaviour and layout of your stretchy header, just override the method `-didChangeStretchFactor:` in your subclass, where you can adjust it by using the `stretchFactor`. To get a more detailed description of the properties, please have a look at the source code. There are also a few usage examples in the example project. You can also take them as a reference for your own stretchy headers.
  63. ## Example project
  64. To run the example project, clone the repo and open the workspace file `GSKStretchyHeaderView.xcworkspace`.
  65. You can also use `pod try GSKStretchyHeaderView`.
  66. ## Installation
  67. GSKStretchyHeaderView is available through [CocoaPods]( To install it, simply add the following line to your Podfile, [you can check the Example Podfile to see how it looks like](
  68. ```ruby
  69. pod "GSKStretchyHeaderView"
  70. ```
  71. GSKStretchyHeaderView is also available through [Carthage](). To install it, just add this line to your `Cartfile:
  72. ```
  73. github "gskbyte/GSKStretchyHeaderView"
  74. ```
  75. and run
  76. ```bash
  77. carthage update GSKStretchyHeaderView
  78. ```
  79. ## Author
  80. Jose Alcalá Correa,
  81. ## License
  82. GSKStretchyHeaderView is available under the MIT license. See the LICENSE file for more info.
  83. ## [Changelog](