Fade UITableView’s Edges

It now works on all tableviews – even if they are part of bigger screen.
It works regardless of the background or whatever is behind the tableview.
The mask changes depends on the position of the table view – when scrolled to top only the bottom faded, in when scrolled to bottom only top is faded…
1. Start by importing
QuartzCore and setting a mask layer in your controller:

1

2

3

4

5

6

7

#import "UIKit/UIKit.h";

#import "QuartzCore/QuartzCore.h";

@interfacemViewController: UIViewController

.

.

@end

2. Add this to
viewWillAppear:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

-(void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

if(!self.tableView.layer.mask)

{

maskLayer=[CAGradientLayerlayer];

maskLayer.locations=@[[NSNumber numberWithFloat:0.0],

[NSNumber numberWithFloat:0.2],

[NSNumber numberWithFloat:0.8],

[NSNumber numberWithFloat:1.0]];

maskLayer.bounds=CGRectMake(0,0,

self.tableView.frame.size.width,

self.tableView.frame.size.height);

maskLayer.anchorPoint=CGPointZero;

self.tableView.layer.mask=maskLayer;

}

[self scrollViewDidScroll:self.tableView];

}

3. Make sure you are a delegate of
UIScrollViewDelegate by adding it in the .h of your controller: