|
8 | 8 |
|
9 | 9 | #import "M2DWebViewController.h" |
10 | 10 |
|
| 11 | +static const CGSize M2DArrorIconSize = {18, 18}; |
| 12 | + |
| 13 | +typedef NS_ENUM(NSUInteger, ArrorIconDirection) { |
| 14 | + ArrorIconDirectionLeft, |
| 15 | + ArrorIconDirectionRight |
| 16 | +}; |
| 17 | + |
| 18 | +@implementation UIImage (M2DArrowIcon) |
| 19 | + |
| 20 | ++ (UIImage *)m2d_arrowIconWithDirection:(ArrorIconDirection)direction size:(CGSize)size |
| 21 | +{ |
| 22 | + if (CGSizeEqualToSize(size, CGSizeZero)) { |
| 23 | + return [[UIImage alloc] init]; |
| 24 | + } |
| 25 | + |
| 26 | + UIGraphicsBeginImageContextWithOptions(size, NO, 0); |
| 27 | + CGContextRef context = UIGraphicsGetCurrentContext(); |
| 28 | + CGRect rect = {CGPointZero, size}; |
| 29 | + |
| 30 | + CGContextSaveGState(context); |
| 31 | + CGContextBeginPath(context); |
| 32 | + |
| 33 | + if (direction == ArrorIconDirectionRight) { |
| 34 | + CGContextMoveToPoint(context, 0, 0); |
| 35 | + CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMidY(rect)); |
| 36 | + CGContextAddLineToPoint(context, 0, CGRectGetMaxY(rect)); |
| 37 | + } else { |
| 38 | + CGContextMoveToPoint(context, CGRectGetMaxX(rect), 0); |
| 39 | + CGContextAddLineToPoint(context, 0, CGRectGetMidY(rect)); |
| 40 | + CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMaxY(rect)); |
| 41 | + } |
| 42 | + |
| 43 | + CGContextClosePath(context); |
| 44 | + CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); |
| 45 | + CGContextFillPath(context); |
| 46 | + CGContextRestoreGState(context); |
| 47 | + |
| 48 | + UIImage *icon = UIGraphicsGetImageFromCurrentImageContext(); |
| 49 | + UIGraphicsEndImageContext(); |
| 50 | + |
| 51 | + return icon; |
| 52 | +} |
| 53 | + |
| 54 | +@end |
| 55 | + |
| 56 | + |
| 57 | +//////////////////////////////////////////////////////////////////////////////// |
| 58 | + |
| 59 | + |
11 | 60 | @interface M2DWebViewController () |
12 | 61 |
|
13 | 62 | @end |
@@ -68,8 +117,8 @@ - (void)viewWillAppear:(BOOL)animated |
68 | 117 | [self.navigationController setToolbarHidden:NO animated:YES]; |
69 | 118 | if (goBackButton_ == nil) { |
70 | 119 | NSArray *toolbarItems = nil; |
71 | | - goBackButton_ = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithContentsOfFile:[self getFilePath:@"M2DWebViewController_left.png"]] style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)]; |
72 | | - goForwardButton_ = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithContentsOfFile:[self getFilePath:@"M2DWebViewController_right.png"]] style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)]; |
| 120 | + goBackButton_ = [[UIBarButtonItem alloc] initWithImage:[UIImage m2d_arrowIconWithDirection:ArrorIconDirectionLeft size:M2DArrorIconSize] style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)]; |
| 121 | + goForwardButton_ = [[UIBarButtonItem alloc] initWithImage:[UIImage m2d_arrowIconWithDirection:ArrorIconDirectionRight size:M2DArrorIconSize] style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)]; |
73 | 122 | UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; |
74 | 123 | UIBarButtonItem *fixedSpace19 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; |
75 | 124 | fixedSpace19.width = 19; |
|
0 commit comments