Created
August 16, 2013 05:56
-
-
Save rickharrison/6247614 to your computer and use it in GitHub Desktop.
iOS 7 Messages Gradient Experimentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NRTRootViewController.m | |
// GradientTableView | |
// | |
// Created by Rick Harrison on 8/15/13. | |
// Copyright (c) 2013 Rick Harrison. All rights reserved. | |
// | |
#import "NRTRootViewController.h" | |
@interface NRTRootViewController () <UITableViewDataSource, UITableViewDelegate> | |
@end | |
@implementation NRTRootViewController | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | |
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { | |
} | |
return self; | |
} | |
- (void)loadView { | |
UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; | |
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gradient"]]; | |
imageView.frame = CGRectMake(0, 0, 320, 568); | |
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; | |
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
tableView.backgroundColor = [UIColor clearColor]; | |
tableView.dataSource = self; | |
tableView.delegate = self; | |
tableView.separatorStyle = UITableViewCellSeparatorStyleNone; | |
[view addSubview:imageView]; | |
[view addSubview:tableView]; | |
self.view = view; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
} | |
#pragma mark - | |
#pragma mark Table View Data Source | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
return 100; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
static NSString *identifier = @"Identifier"; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; | |
if (cell == nil) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; | |
cell.backgroundColor = [UIColor clearColor]; | |
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.contentView.bounds]; | |
backgroundView.backgroundColor = [UIColor whiteColor]; | |
/* | |
* Draw layer mask for the background | |
*/ | |
UIGraphicsBeginImageContextWithOptions(backgroundView.bounds.size, NO, 0.0); | |
CGContextRef ctx = UIGraphicsGetCurrentContext(); | |
if (ctx) { | |
CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); | |
CGContextFillRect(ctx, CGRectMake(0.0, 0.0, 100.0, backgroundView.bounds.size.height)); | |
CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); | |
CGContextFillRect(ctx, CGRectMake(100.0, 0.0, 100.0, 10.0)); | |
CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); | |
CGContextFillRect(ctx, CGRectMake(100.0, backgroundView.bounds.size.height - 10.0, 100.0, 10.0)); | |
CGContextSetFillColorWithColor(ctx, [UIColor clearColor].CGColor); | |
CGContextFillRect(ctx, CGRectMake(100.0, 10.0, 100.0, backgroundView.bounds.size.height - 20)); | |
CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor); | |
CGContextFillRect(ctx, CGRectMake(200.0, 0.0, 120.0, backgroundView.bounds.size.height)); | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
[backgroundView addSubview:[[UIImageView alloc] initWithImage:image]]; | |
CALayer *mask = [CALayer layer]; | |
mask.contents = (id)image.CGImage; | |
mask.frame = backgroundView.bounds; | |
[backgroundView.layer setMask:mask]; | |
} | |
/* | |
* Add the subviews to the tree | |
*/ | |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 10.0, 100.0, 24.0)]; | |
label.font = [UIFont systemFontOfSize:13.0]; | |
label.textAlignment = NSTextAlignmentCenter; | |
label.textColor = [UIColor whiteColor]; | |
label.text = @"Hi Matt"; | |
[cell.contentView addSubview:backgroundView]; | |
[cell.contentView addSubview:label]; | |
} | |
return cell; | |
} | |
#pragma mark - | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment