Adjust update view header to iOS 7 style

This commit is contained in:
Andreas Linde 2013-08-17 17:24:28 +02:00
parent 5b43944128
commit 5dd995d1b2
3 changed files with 54 additions and 9 deletions

View File

@ -31,10 +31,33 @@
#import <UIKit/UIKit.h>
#ifndef __IPHONE_6_1
#define __IPHONE_6_1 60100
#endif
#if __IPHONE_OS_VERSION_MIN_ALLOWED > __IPHONE_6_1
#warning Remove the option to adjust the button style. We are now iOS 7 only.
#endif
/**
* Header style depending on the iOS version
*/
typedef NS_ENUM(NSUInteger, BITAppStoreHeaderStyle) {
/**
* Default is iOS 6 style
*/
BITAppStoreHeaderStyleDefault = 0,
/**
* Draw header in the iOS 7 style
*/
BITAppStoreHeaderStyleOS7 = 1
};
@interface BITAppStoreHeader : UIView
@property (nonatomic, copy) NSString *headerText;
@property (nonatomic, copy) NSString *subHeaderText;
@property (nonatomic, strong) UIImage *iconImage;
@property (nonatomic, assign) BITAppStoreHeaderStyle style;
@end

View File

@ -36,7 +36,8 @@
#define kLightGrayColor BIT_RGBCOLOR(235, 235, 235)
#define kDarkGrayColor BIT_RGBCOLOR(186, 186, 186)
#define kWhiteBackgroundColor BIT_RGBCOLOR(245, 245, 245)
#define kWhiteBackgroundColorDefault BIT_RGBCOLOR(245, 245, 245)
#define kWhiteBackgroundColorOS7 BIT_RGBCOLOR(255, 255, 255)
#define kImageHeight 72
#define kImageBorderRadius 12
#define kImageLeftMargin 14
@ -54,7 +55,8 @@
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.backgroundColor = kWhiteBackgroundColor;
self.backgroundColor = kWhiteBackgroundColorDefault;
self.style = BITAppStoreHeaderStyleDefault;
}
return self;
}
@ -66,20 +68,35 @@
CGRect bounds = self.bounds;
CGContextRef context = UIGraphicsGetCurrentContext();
// draw the gradient
NSArray *colors = [NSArray arrayWithObjects:(id)kDarkGrayColor.CGColor, (id)kLightGrayColor.CGColor, nil];
CGGradientRef gradient = CGGradientCreateWithColors(CGColorGetColorSpace((__bridge CGColorRef)[colors objectAtIndex:0]), (__bridge CFArrayRef)colors, (CGFloat[2]){0, 1});
CGPoint top = CGPointMake(CGRectGetMidX(bounds), bounds.size.height - 3);
CGPoint bottom = CGPointMake(CGRectGetMidX(bounds), CGRectGetMaxY(bounds));
CGContextDrawLinearGradient(context, gradient, top, bottom, 0);
CGGradientRelease(gradient);
if (self.style == BITAppStoreHeaderStyleDefault) {
// draw the gradient
NSArray *colors = [NSArray arrayWithObjects:(id)kDarkGrayColor.CGColor, (id)kLightGrayColor.CGColor, nil];
CGGradientRef gradient = CGGradientCreateWithColors(CGColorGetColorSpace((__bridge CGColorRef)[colors objectAtIndex:0]), (__bridge CFArrayRef)colors, (CGFloat[2]){0, 1});
CGPoint top = CGPointMake(CGRectGetMidX(bounds), bounds.size.height - 3);
CGPoint bottom = CGPointMake(CGRectGetMidX(bounds), CGRectGetMaxY(bounds));
CGContextDrawLinearGradient(context, gradient, top, bottom, 0);
CGGradientRelease(gradient);
} else {
// draw the line
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 1.0);
CGContextSetStrokeColorWithColor(ctx, kDarkGrayColor.CGColor);
CGContextMoveToPoint(ctx, 0, CGRectGetMaxY(bounds));
CGContextAddLineToPoint( ctx, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
CGContextStrokePath(ctx);
}
// icon
[_iconImage drawAtPoint:CGPointMake(kImageLeftMargin, kImageTopMargin)];
[super drawRect:rect];
}
- (void)layoutSubviews {
if (self.style == BITAppStoreHeaderStyleOS7)
self.backgroundColor = kWhiteBackgroundColorOS7;
[super layoutSubviews];
CGFloat globalWidth = self.frame.size.width;

View File

@ -270,6 +270,11 @@
[self.tableView addSubview:topView];
_appStoreHeader = [[BITAppStoreHeader alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, kAppStoreViewHeight)];
if ([self.updateManager isPreiOS7Environment]) {
_appStoreHeader.style = BITAppStoreHeaderStyleDefault;
} else {
_appStoreHeader.style = BITAppStoreHeaderStyleOS7;
}
[self updateAppStoreHeader];
NSString *iconString = nil;