forked from vfr/Reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThumbsMainToolbar.m
More file actions
169 lines (128 loc) · 6.51 KB
/
ThumbsMainToolbar.m
File metadata and controls
169 lines (128 loc) · 6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//
// ThumbsMainToolbar.m
// Reader v2.9.0
//
// Created by Julius Oklamcak on 2011-09-01.
// Copyright © 2011-2015 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "ReaderConstants.h"
#import "ThumbsMainToolbar.h"
@implementation ThumbsMainToolbar
#pragma mark - Constants
#define BUTTON_X 8.0f
#define BUTTON_Y 8.0f
#define BUTTON_SPACE 8.0f
#define BUTTON_HEIGHT 30.0f
#define BUTTON_FONT_SIZE 15.0f
#define TEXT_BUTTON_PADDING 24.0f
#define SHOW_CONTROL_WIDTH 78.0f
#define ICON_BUTTON_WIDTH 40.0f
#define TITLE_FONT_SIZE 19.0f
#define TITLE_HEIGHT 28.0f
#pragma mark - Properties
@synthesize delegate;
#pragma mark - ThumbsMainToolbar instance methods
- (instancetype)initWithFrame:(CGRect)frame
{
return [self initWithFrame:frame title:nil];
}
- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
if ((self = [super initWithFrame:frame]))
{
CGFloat viewWidth = self.bounds.size.width; // Toolbar view width
#if (READER_FLAT_UI == TRUE) // Option
UIImage *buttonH = nil; UIImage *buttonN = nil;
#else
UIImage *buttonH = [[UIImage imageNamed:@"Reader-Button-H"] stretchableImageWithLeftCapWidth:5 topCapHeight:0];
UIImage *buttonN = [[UIImage imageNamed:@"Reader-Button-N"] stretchableImageWithLeftCapWidth:5 topCapHeight:0];
#endif // end of READER_FLAT_UI Option
BOOL largeDevice = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
const CGFloat buttonSpacing = BUTTON_SPACE; //const CGFloat iconButtonWidth = ICON_BUTTON_WIDTH;
CGFloat titleX = BUTTON_X; CGFloat titleWidth = (viewWidth - (titleX + titleX));
CGFloat leftButtonX = BUTTON_X; // Left-side button start X position
UIFont *doneButtonFont = [UIFont systemFontOfSize:BUTTON_FONT_SIZE];
NSString *doneButtonText = NSLocalizedString(@"Done", @"button text");
CGSize doneButtonSize = [doneButtonText sizeWithAttributes:@{NSFontAttributeName : doneButtonFont}];
CGFloat doneButtonWidth = (ceil(doneButtonSize.width) + TEXT_BUTTON_PADDING);
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(leftButtonX, BUTTON_Y, doneButtonWidth, BUTTON_HEIGHT);
[doneButton setTitleColor:[UIColor colorWithWhite:0.0f alpha:1.0f] forState:UIControlStateNormal];
[doneButton setTitleColor:[UIColor colorWithWhite:1.0f alpha:1.0f] forState:UIControlStateHighlighted];
[doneButton setTitle:doneButtonText forState:UIControlStateNormal]; doneButton.titleLabel.font = doneButtonFont;
[doneButton addTarget:self action:@selector(doneButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[doneButton setBackgroundImage:buttonH forState:UIControlStateHighlighted];
[doneButton setBackgroundImage:buttonN forState:UIControlStateNormal];
doneButton.autoresizingMask = UIViewAutoresizingNone;
//doneButton.backgroundColor = [UIColor grayColor];
doneButton.exclusiveTouch = YES;
[self addSubview:doneButton]; //leftButtonX += (doneButtonWidth + buttonSpacing);
titleX += (doneButtonWidth + buttonSpacing); titleWidth -= (doneButtonWidth + buttonSpacing);
#if (READER_BOOKMARKS == TRUE) // Option
CGFloat showControlX = (viewWidth - (SHOW_CONTROL_WIDTH + buttonSpacing));
UIImage *thumbsImage = [UIImage imageNamed:@"Reader-Thumbs"];
UIImage *bookmarkImage = [UIImage imageNamed:@"Reader-Mark-Y"];
NSArray *buttonItems = [NSArray arrayWithObjects:thumbsImage, bookmarkImage, nil];
BOOL useTint = [self respondsToSelector:@selector(tintColor)]; // iOS 7 and up
UISegmentedControl *showControl = [[UISegmentedControl alloc] initWithItems:buttonItems];
showControl.frame = CGRectMake(showControlX, BUTTON_Y, SHOW_CONTROL_WIDTH, BUTTON_HEIGHT);
showControl.tintColor = (useTint ? [UIColor blackColor] : [UIColor colorWithWhite:0.8f alpha:1.0f]);
showControl.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
//showControl.segmentedControlStyle = UISegmentedControlStyleBar;
showControl.selectedSegmentIndex = 0; // Default segment index
//showControl.backgroundColor = [UIColor grayColor];
showControl.exclusiveTouch = YES;
[showControl addTarget:self action:@selector(showControlTapped:) forControlEvents:UIControlEventValueChanged];
[self addSubview:showControl];
titleWidth -= (SHOW_CONTROL_WIDTH + buttonSpacing);
#endif // end of READER_BOOKMARKS Option
if (largeDevice == YES) // Show document filename in toolbar
{
CGRect titleRect = CGRectMake(titleX, BUTTON_Y, titleWidth, TITLE_HEIGHT);
UILabel *titleLabel = [[UILabel alloc] initWithFrame:titleRect];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.font = [UIFont systemFontOfSize:TITLE_FONT_SIZE];
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
titleLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
titleLabel.textColor = [UIColor colorWithWhite:0.0f alpha:1.0f];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.adjustsFontSizeToFitWidth = YES;
titleLabel.minimumScaleFactor = 0.75f;
titleLabel.text = title;
#if (READER_FLAT_UI == FALSE) // Option
titleLabel.shadowColor = [UIColor colorWithWhite:0.65f alpha:1.0f];
titleLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
#endif // end of READER_FLAT_UI Option
[self addSubview:titleLabel];
}
}
return self;
}
#pragma mark - UISegmentedControl action methods
- (void)showControlTapped:(UISegmentedControl *)control
{
[delegate tappedInToolbar:self showControl:control];
}
#pragma mark - UIButton action methods
- (void)doneButtonTapped:(UIButton *)button
{
[delegate tappedInToolbar:self doneButton:button];
}
@end