123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #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
- #define COLOR_BAR [UIColor colorWithRed:(248.0f/255.0f) green:(248.0f/255.0f) blue:(248.0f/255.0f) alpha:1.0]
- #define COLOR_ARANCIO [UIColor colorWithRed:241.0/255.0 green:90.0/255.0 blue:34.0/255.0 alpha:1.0]
- #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;
- #if (READER_FLAT_UI == TRUE)
- 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
- BOOL largeDevice = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
- const CGFloat buttonSpacing = BUTTON_SPACE;
- CGFloat titleX = BUTTON_X; CGFloat titleWidth = (viewWidth - (titleX + titleX));
- CGFloat leftButtonX = BUTTON_X;
- UIFont *doneButtonFont = [UIFont systemFontOfSize:BUTTON_FONT_SIZE];
- NSString *doneButtonText = NSLocalizedString(@"Done", @"button");
-
- CGSize doneButtonSize = [doneButtonText sizeWithAttributes:@{NSFontAttributeName: doneButtonFont}];
- CGFloat doneButtonWidth = (doneButtonSize.width + TEXT_BUTTON_PADDING);
- UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
- doneButton.frame = CGRectMake(leftButtonX, BUTTON_Y, doneButtonWidth, BUTTON_HEIGHT);
- [doneButton setTitleColor:COLOR_ARANCIO 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.exclusiveTouch = YES;
- [self addSubview:doneButton];
- titleX += (doneButtonWidth + buttonSpacing); titleWidth -= (doneButtonWidth + buttonSpacing);
- #if (READER_BOOKMARKS == TRUE)
- 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)];
- 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.tintColor = COLOR_ARANCIO;
-
- showControl.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
-
- showControl.selectedSegmentIndex = 0;
- showControl.exclusiveTouch = YES;
- [showControl addTarget:self action:@selector(showControlTapped:) forControlEvents:UIControlEventValueChanged];
- [self addSubview:showControl];
- titleWidth -= (SHOW_CONTROL_WIDTH + buttonSpacing);
- #endif
- if (largeDevice == YES)
- {
- 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)
- titleLabel.shadowColor = [UIColor colorWithWhite:0.65f alpha:1.0f];
- titleLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
- #endif
- [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
|