Skip to content

Commit cd404c4

Browse files
committed
Add styles for iOS 7
1 parent 7ad153c commit cd404c4

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

RMSTokenView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "RMSTokenView"
3-
s.version = "1.0.2"
3+
s.version = "1.0.3"
44
s.summary = "RMSTokenView is a text-field like view that handles tokens as seen in the Mail app."
55
s.homepage = "https://github.com/RoleModel/RMSTokenView"
66
s.license = { :type => 'MIT', :file => 'LICENSE' }

RMSTokenView/RMSTokenView.m

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#import "RMSTokenView.h"
1010
#import "RMSTokenConstraintManager.h"
1111

12+
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
13+
#define iOS_7_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")
14+
1215
void *RMSTokenSelectionContext = &RMSTokenSelectionContext;
1316
NSString *RMSBackspaceUnicodeString = @"\u200B";
1417

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

1922
@property (nonatomic, strong) UILabel *summaryLabel;
2023

21-
@property (nonatomic, strong) NSArray *contentConstraints;
22-
2324
@property (nonatomic, strong) NSMutableArray *tokenViews;
2425
@property (nonatomic, strong) NSMutableArray *tokenLines;
2526
@property (nonatomic, strong) UIButton *selectedToken;
@@ -28,6 +29,10 @@ @interface RMSTokenView()
2829

2930
@property (nonatomic, strong) RMSTokenConstraintManager *constraintManager;
3031

32+
#pragma mark - Token View
33+
@property (nonatomic) CGFloat tokenViewBorderRadius;
34+
@property (nonatomic) BOOL needsGradient;
35+
3136
@end
3237

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

5358
- (void)initialize {
59+
[self setupVersionSpecificProperties];
5460
if (CGRectIsEmpty(self.frame)) {
5561
self.frame = CGRectMake(0, 0, 320, 44);
5662
}
@@ -545,21 +551,26 @@ - (UIImage *)buttonImageWithTopColor:(UIColor *)topColor bottomColor:(UIColor *)
545551
CGContextRef context = UIGraphicsGetCurrentContext();
546552

547553
/* Draw Fill Gradient */
548-
CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:12].CGPath);
554+
CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:self.tokenViewBorderRadius].CGPath);
549555
CGContextClip(context);
550-
551-
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
552-
CGFloat locations[] = { 0.0, 1.0 };
553-
NSArray *colors = @[(__bridge id)topColor.CGColor, (__bridge id)bottomColor.CGColor];
554-
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations);
555-
556-
CGPoint startPoint = CGPointMake(rect.size.width / 2.0, 0);
557-
CGPoint endPoint = CGPointMake(rect.size.width / 2.0, rect.size.height);
558-
559-
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
556+
557+
if (self.needsGradient) {
558+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
559+
CGFloat locations[] = {0.0, 1.0};
560+
NSArray *colors = @[(__bridge id)topColor.CGColor, (__bridge id)bottomColor.CGColor];
561+
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations);
562+
563+
CGPoint startPoint = CGPointMake(rect.size.width / 2.0, 0);
564+
CGPoint endPoint = CGPointMake(rect.size.width / 2.0, rect.size.height);
565+
566+
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
567+
} else {
568+
CGContextSetFillColorWithColor(context, topColor.CGColor);
569+
UIRectFill(rect);
570+
}
560571

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

583+
- (void)setupVersionSpecificProperties {
584+
self.needsGradient = !iOS_7_OR_LATER;
585+
if (iOS_7_OR_LATER) {
586+
self.tokenViewBorderRadius = 7;
587+
} else {
588+
self.tokenViewBorderRadius = 12;
589+
}
590+
}
591+
572592
#pragma mark - Accessors
573593

574594
- (void)setText:(NSString *)text

RMSTokenView/RMSViewController.m

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,13 @@ @interface RMSViewController ()
1414

1515
@implementation RMSViewController
1616

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

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

28-
- (void)didReceiveMemoryWarning
29-
{
30-
[super didReceiveMemoryWarning];
31-
// Dispose of any resources that can be recreated.
32-
}
33-
3426
@end

0 commit comments

Comments
 (0)