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+
1215void *RMSTokenSelectionContext = &RMSTokenSelectionContext;
1316NSString *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
0 commit comments