Skip to content

Commit 632ae33

Browse files
committed
change arrow image feature
1 parent f8b9bb1 commit 632ae33

5 files changed

Lines changed: 54 additions & 4 deletions

File tree

Example/M2DWebViewController.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
2525
D7327120609861F29FC56149 /* libPods-M2DWebViewController.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E6F64939D387F863473C21F1 /* libPods-M2DWebViewController.a */; };
2626
E99F030919EBFBF400B76837 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E99F030819EBFBF400B76837 /* WebKit.framework */; };
27-
E9A1D19D1A3A2901006807DE /* M2DWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E9A1D19B1A3A2901006807DE /* M2DWebViewController.m */; };
2827
/* End PBXBuildFile section */
2928

3029
/* Begin PBXContainerItemProxy section */
@@ -392,7 +391,6 @@
392391
buildActionMask = 2147483647;
393392
files = (
394393
6003F59E195388D20070C39A /* M2DAppDelegate.m in Sources */,
395-
E9A1D19D1A3A2901006807DE /* M2DWebViewController.m in Sources */,
396394
6003F5A7195388D20070C39A /* M2DViewController.m in Sources */,
397395
6003F59A195388D20070C39A /* main.m in Sources */,
398396
);

Example/M2DWebViewController/Base.lproj/Main.storyboard

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,24 @@
3535
<action selector="show:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="fa5-Oa-Wie"/>
3636
</connections>
3737
</button>
38+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XGM-5e-D8s">
39+
<rect key="frame" x="113" y="352" width="85" height="30"/>
40+
<state key="normal" title="arrow image">
41+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
42+
</state>
43+
<connections>
44+
<action selector="showWithArrowImage:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="dV2-vy-m0m"/>
45+
</connections>
46+
</button>
3847
</subviews>
3948
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
4049
<constraints>
4150
<constraint firstAttribute="centerY" secondItem="CUn-xZ-2cR" secondAttribute="centerY" constant="14" id="8kA-83-yxi"/>
51+
<constraint firstAttribute="centerY" secondItem="XGM-5e-D8s" secondAttribute="centerY" constant="-83" id="Ji3-R8-q4W"/>
4252
<constraint firstAttribute="centerX" secondItem="XrB-vd-6Xg" secondAttribute="centerX" id="gI4-4c-mzC"/>
4353
<constraint firstAttribute="centerY" secondItem="XrB-vd-6Xg" secondAttribute="centerY" constant="-37" id="leK-Mm-sGG"/>
4454
<constraint firstAttribute="centerX" secondItem="CUn-xZ-2cR" secondAttribute="centerX" constant="4.5" id="vNI-4g-5O5"/>
55+
<constraint firstAttribute="centerX" secondItem="XGM-5e-D8s" secondAttribute="centerX" constant="4.5" id="wbI-Kh-xap"/>
4556
</constraints>
4657
</view>
4758
<navigationItem key="navigationItem" id="cLe-9W-urx"/>

Example/M2DWebViewController/M2DViewController.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,30 @@ - (IBAction)show2:(id)sender
4545
[self.navigationController pushViewController:viewController animated:YES];
4646
}
4747

48+
- (IBAction)showWithArrowImage:(id)sender
49+
{
50+
CGSize size = CGSizeMake(18, 18);
51+
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
52+
CGContextRef context = UIGraphicsGetCurrentContext();
53+
CGRect rect = {CGPointZero, size};
54+
55+
CGContextSaveGState(context);
56+
CGContextBeginPath(context);
57+
58+
CGContextMoveToPoint(context, 0, 0);
59+
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMidY(rect));
60+
CGContextAddLineToPoint(context, 0, CGRectGetMaxY(rect));
61+
62+
CGContextClosePath(context);
63+
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
64+
CGContextFillPath(context);
65+
CGContextRestoreGState(context);
66+
67+
UIImage *icon = UIGraphicsGetImageFromCurrentImageContext();
68+
UIGraphicsEndImageContext();
69+
70+
M2DWebViewController *viewController = [[M2DWebViewController alloc] initWithURL:[NSURL URLWithString:@"https://github.com/0x0c/M2DWebViewController"] type:M2DWebViewTypeUIKit backArrowImage:icon forwardArrowImage:icon];
71+
[self.navigationController pushViewController:viewController animated:YES];
72+
}
73+
4874
@end

Pod/Classes/M2DWebViewController/M2DWebViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef NS_ENUM(NSUInteger, M2DWebViewType) {
3535
@property (nonatomic, copy) void (^actionButtonPressedHandler)(NSString *pageTitle, NSURL *url);
3636

3737
- (instancetype)initWithURL:(NSURL *)url type:(M2DWebViewType)type;
38+
- (instancetype)initWithURL:(NSURL *)url type:(M2DWebViewType)type backArrowImage:(UIImage *)backArrowImage forwardArrowImage:(UIImage *)forwardArrowImage;
3839
- (void)goForward:(id)sender;
3940
- (void)goBack:(id)sender;
4041
- (void)refresh:(id)sender;

Pod/Classes/M2DWebViewController/M2DWebViewController.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ + (UIImage *)m2d_arrowIconWithDirection:(M2DArrowIconDirection)direction size:(C
5959

6060
@interface M2DWebViewController ()
6161

62+
@property (nonatomic, copy) UIImage *backArrowImage;
63+
@property (nonatomic, copy) UIImage *forwardArrowImage;
64+
6265
@end
6366

6467
@implementation M2DWebViewController
@@ -78,6 +81,17 @@ - (id)initWithURL:(NSURL *)url type:(M2DWebViewType)type
7881
return self;
7982
}
8083

84+
- (instancetype)initWithURL:(NSURL *)url type:(M2DWebViewType)type backArrowImage:(UIImage *)backArrowImage forwardArrowImage:(UIImage *)forwardArrowImage
85+
{
86+
self = [self initWithURL:url type:type];
87+
if (self) {
88+
self.backArrowImage = backArrowImage;
89+
self.forwardArrowImage = forwardArrowImage;
90+
}
91+
92+
return self;
93+
}
94+
8195
- (void)dealloc
8296
{
8397
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
@@ -117,8 +131,8 @@ - (void)viewWillAppear:(BOOL)animated
117131
[self.navigationController setToolbarHidden:NO animated:YES];
118132
if (goBackButton_ == nil) {
119133
NSArray *toolbarItems = nil;
120-
goBackButton_ = [[UIBarButtonItem alloc] initWithImage:[UIImage m2d_arrowIconWithDirection:M2DArrowIconDirectionLeft size:M2DArrowIconSize] style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)];
121-
goForwardButton_ = [[UIBarButtonItem alloc] initWithImage:[UIImage m2d_arrowIconWithDirection:M2DArrowIconDirectionRight size:M2DArrowIconSize] style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)];
134+
goBackButton_ = [[UIBarButtonItem alloc] initWithImage:self.backArrowImage ?: [UIImage m2d_arrowIconWithDirection:M2DArrowIconDirectionLeft size:M2DArrowIconSize] style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)];
135+
goForwardButton_ = [[UIBarButtonItem alloc] initWithImage:self.forwardArrowImage ?: [UIImage m2d_arrowIconWithDirection:M2DArrowIconDirectionRight size:M2DArrowIconSize] style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)];
122136
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
123137
UIBarButtonItem *fixedSpace19 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
124138
fixedSpace19.width = 19;

0 commit comments

Comments
 (0)