mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Adjust update view header to iOS 7 style
This commit is contained in:
parent
5b43944128
commit
5dd995d1b2
@ -31,10 +31,33 @@
|
|||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#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
|
@interface BITAppStoreHeader : UIView
|
||||||
|
|
||||||
@property (nonatomic, copy) NSString *headerText;
|
@property (nonatomic, copy) NSString *headerText;
|
||||||
@property (nonatomic, copy) NSString *subHeaderText;
|
@property (nonatomic, copy) NSString *subHeaderText;
|
||||||
@property (nonatomic, strong) UIImage *iconImage;
|
@property (nonatomic, strong) UIImage *iconImage;
|
||||||
|
@property (nonatomic, assign) BITAppStoreHeaderStyle style;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -36,7 +36,8 @@
|
|||||||
|
|
||||||
#define kLightGrayColor BIT_RGBCOLOR(235, 235, 235)
|
#define kLightGrayColor BIT_RGBCOLOR(235, 235, 235)
|
||||||
#define kDarkGrayColor BIT_RGBCOLOR(186, 186, 186)
|
#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 kImageHeight 72
|
||||||
#define kImageBorderRadius 12
|
#define kImageBorderRadius 12
|
||||||
#define kImageLeftMargin 14
|
#define kImageLeftMargin 14
|
||||||
@ -54,7 +55,8 @@
|
|||||||
- (id)initWithFrame:(CGRect)frame {
|
- (id)initWithFrame:(CGRect)frame {
|
||||||
if ((self = [super initWithFrame:frame])) {
|
if ((self = [super initWithFrame:frame])) {
|
||||||
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
||||||
self.backgroundColor = kWhiteBackgroundColor;
|
self.backgroundColor = kWhiteBackgroundColorDefault;
|
||||||
|
self.style = BITAppStoreHeaderStyleDefault;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -66,20 +68,35 @@
|
|||||||
CGRect bounds = self.bounds;
|
CGRect bounds = self.bounds;
|
||||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||||
|
|
||||||
// draw the gradient
|
if (self.style == BITAppStoreHeaderStyleDefault) {
|
||||||
NSArray *colors = [NSArray arrayWithObjects:(id)kDarkGrayColor.CGColor, (id)kLightGrayColor.CGColor, nil];
|
// draw the gradient
|
||||||
CGGradientRef gradient = CGGradientCreateWithColors(CGColorGetColorSpace((__bridge CGColorRef)[colors objectAtIndex:0]), (__bridge CFArrayRef)colors, (CGFloat[2]){0, 1});
|
NSArray *colors = [NSArray arrayWithObjects:(id)kDarkGrayColor.CGColor, (id)kLightGrayColor.CGColor, nil];
|
||||||
CGPoint top = CGPointMake(CGRectGetMidX(bounds), bounds.size.height - 3);
|
CGGradientRef gradient = CGGradientCreateWithColors(CGColorGetColorSpace((__bridge CGColorRef)[colors objectAtIndex:0]), (__bridge CFArrayRef)colors, (CGFloat[2]){0, 1});
|
||||||
CGPoint bottom = CGPointMake(CGRectGetMidX(bounds), CGRectGetMaxY(bounds));
|
CGPoint top = CGPointMake(CGRectGetMidX(bounds), bounds.size.height - 3);
|
||||||
CGContextDrawLinearGradient(context, gradient, top, bottom, 0);
|
CGPoint bottom = CGPointMake(CGRectGetMidX(bounds), CGRectGetMaxY(bounds));
|
||||||
CGGradientRelease(gradient);
|
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
|
// icon
|
||||||
[_iconImage drawAtPoint:CGPointMake(kImageLeftMargin, kImageTopMargin)];
|
[_iconImage drawAtPoint:CGPointMake(kImageLeftMargin, kImageTopMargin)];
|
||||||
|
|
||||||
|
[super drawRect:rect];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)layoutSubviews {
|
- (void)layoutSubviews {
|
||||||
|
if (self.style == BITAppStoreHeaderStyleOS7)
|
||||||
|
self.backgroundColor = kWhiteBackgroundColorOS7;
|
||||||
|
|
||||||
[super layoutSubviews];
|
[super layoutSubviews];
|
||||||
|
|
||||||
CGFloat globalWidth = self.frame.size.width;
|
CGFloat globalWidth = self.frame.size.width;
|
||||||
|
@ -270,6 +270,11 @@
|
|||||||
[self.tableView addSubview:topView];
|
[self.tableView addSubview:topView];
|
||||||
|
|
||||||
_appStoreHeader = [[BITAppStoreHeader alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, kAppStoreViewHeight)];
|
_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];
|
[self updateAppStoreHeader];
|
||||||
|
|
||||||
NSString *iconString = nil;
|
NSString *iconString = nil;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user