Skip to content

Commit

Permalink
Add styles for iOS 7
Browse files Browse the repository at this point in the history
  • Loading branch information
rcdilorenzo committed Sep 19, 2013
1 parent 7ad153c commit cd404c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion RMSTokenView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RMSTokenView"
s.version = "1.0.2"
s.version = "1.0.3"
s.summary = "RMSTokenView is a text-field like view that handles tokens as seen in the Mail app."
s.homepage = "https://github.com/RoleModel/RMSTokenView"
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
48 changes: 34 additions & 14 deletions RMSTokenView/RMSTokenView.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#import "RMSTokenView.h"
#import "RMSTokenConstraintManager.h"

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define iOS_7_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")

void *RMSTokenSelectionContext = &RMSTokenSelectionContext;
NSString *RMSBackspaceUnicodeString = @"\u200B";

Expand All @@ -18,8 +21,6 @@ @interface RMSTokenView()

@property (nonatomic, strong) UILabel *summaryLabel;

@property (nonatomic, strong) NSArray *contentConstraints;

@property (nonatomic, strong) NSMutableArray *tokenViews;
@property (nonatomic, strong) NSMutableArray *tokenLines;
@property (nonatomic, strong) UIButton *selectedToken;
Expand All @@ -28,6 +29,10 @@ @interface RMSTokenView()

@property (nonatomic, strong) RMSTokenConstraintManager *constraintManager;

#pragma mark - Token View
@property (nonatomic) CGFloat tokenViewBorderRadius;
@property (nonatomic) BOOL needsGradient;

@end

@implementation RMSTokenView
Expand All @@ -51,6 +56,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
}

- (void)initialize {
[self setupVersionSpecificProperties];
if (CGRectIsEmpty(self.frame)) {
self.frame = CGRectMake(0, 0, 320, 44);
}
Expand Down Expand Up @@ -545,21 +551,26 @@ - (UIImage *)buttonImageWithTopColor:(UIColor *)topColor bottomColor:(UIColor *)
CGContextRef context = UIGraphicsGetCurrentContext();

/* Draw Fill Gradient */
CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:12].CGPath);
CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:self.tokenViewBorderRadius].CGPath);
CGContextClip(context);

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = { 0.0, 1.0 };
NSArray *colors = @[(__bridge id)topColor.CGColor, (__bridge id)bottomColor.CGColor];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations);

CGPoint startPoint = CGPointMake(rect.size.width / 2.0, 0);
CGPoint endPoint = CGPointMake(rect.size.width / 2.0, rect.size.height);

CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);

if (self.needsGradient) {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = {0.0, 1.0};
NSArray *colors = @[(__bridge id)topColor.CGColor, (__bridge id)bottomColor.CGColor];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations);

CGPoint startPoint = CGPointMake(rect.size.width / 2.0, 0);
CGPoint endPoint = CGPointMake(rect.size.width / 2.0, rect.size.height);

CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
} else {
CGContextSetFillColorWithColor(context, topColor.CGColor);
UIRectFill(rect);
}

/* Draw Stroke */
CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:CGRectInset(rect, 0.2, 0.2) cornerRadius:12].CGPath);
CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:CGRectInset(rect, 0.2, 0.2) cornerRadius:self.tokenViewBorderRadius].CGPath);
CGContextSetStrokeColorWithColor(context, strokeColor.CGColor);
CGContextSetLineWidth(context, 0.5);
CGContextStrokePath(context);
Expand All @@ -569,6 +580,15 @@ - (UIImage *)buttonImageWithTopColor:(UIColor *)topColor bottomColor:(UIColor *)
return [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 14, 0, 14)];
}

- (void)setupVersionSpecificProperties {
self.needsGradient = !iOS_7_OR_LATER;
if (iOS_7_OR_LATER) {
self.tokenViewBorderRadius = 7;
} else {
self.tokenViewBorderRadius = 12;
}
}

#pragma mark - Accessors

- (void)setText:(NSString *)text
Expand Down
10 changes: 1 addition & 9 deletions RMSTokenView/RMSViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ @interface RMSViewController ()

@implementation RMSViewController

- (void)viewDidLoad
{
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)dismissKeyboard {
[self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

0 comments on commit cd404c4

Please sign in to comment.