Skip to content

Commit 16392bc

Browse files
committed
Merge branch 'master' of github.com:0x0c/M2DWebViewController
2 parents 2955edf + 2a971a0 commit 16392bc

7 files changed

Lines changed: 51 additions & 5 deletions

M2DWebViewController.podspec

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ Pod::Spec.new do |s|
2121
s.requires_arc = true
2222

2323
s.source_files = 'Pod/Classes/**/*.{h,m}'
24-
s.resource_bundles = {
25-
'M2DWebViewController' => ['Pod/Assets/**']
26-
}
2724

2825
# s.public_header_files = 'Pod/Classes/**/*.h'
2926
s.frameworks = 'WebKit'

Pod/Assets/.gitkeep

Whitespace-only changes.
-4.08 KB
Binary file not shown.
-4.62 KB
Binary file not shown.
-4.1 KB
Binary file not shown.
-4.67 KB
Binary file not shown.

Pod/Classes/M2DWebViewController/M2DWebViewController.m

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,55 @@
88

99
#import "M2DWebViewController.h"
1010

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+
1160
@interface M2DWebViewController ()
1261

1362
@end
@@ -68,8 +117,8 @@ - (void)viewWillAppear:(BOOL)animated
68117
[self.navigationController setToolbarHidden:NO animated:YES];
69118
if (goBackButton_ == nil) {
70119
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:)];
73122
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
74123
UIBarButtonItem *fixedSpace19 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
75124
fixedSpace19.width = 19;

0 commit comments

Comments
 (0)