SMPageControl.m
19.4 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
//
// SMPageControl.m
// SMPageControl
//
// Created by Jerry Jones on 10/13/12.
// Copyright (c) 2012 Spaceman Labs. All rights reserved.
//
#import "SMPageControl.h"
#if ! __has_feature(objc_arc)
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif
#define DEFAULT_INDICATOR_WIDTH 6.0f
#define DEFAULT_INDICATOR_MARGIN 10.0f
#define DEFAULT_MIN_HEIGHT 36.0f
#define DEFAULT_INDICATOR_WIDTH_LARGE 7.0f
#define DEFAULT_INDICATOR_MARGIN_LARGE 9.0f
#define DEFAULT_MIN_HEIGHT_LARGE 36.0f
typedef NS_ENUM(NSUInteger, SMPageControlImageType) {
SMPageControlImageTypeNormal = 1,
SMPageControlImageTypeCurrent,
SMPageControlImageTypeMask
};
typedef NS_ENUM(NSUInteger, SMPageControlStyleDefaults) {
SMPageControlDefaultStyleClassic = 0,
SMPageControlDefaultStyleModern
};
static SMPageControlStyleDefaults _defaultStyleForSystemVersion;
@interface SMPageControl ()
@property (strong, readonly, nonatomic) NSMutableDictionary *pageNames;
@property (strong, readonly, nonatomic) NSMutableDictionary *pageImages;
@property (strong, readonly, nonatomic) NSMutableDictionary *currentPageImages;
@property (strong, readonly, nonatomic) NSMutableDictionary *pageImageMasks;
@property (strong, readonly, nonatomic) NSMutableDictionary *cgImageMasks;
@property (strong, readwrite, nonatomic) NSArray *pageRects;
// Page Control used for stealing page number localizations for accessibility labels
// I'm not sure I love this technique, but it's the best way to get exact translations for all the languages
// that Apple supports out of the box
@property (nonatomic, strong) UIPageControl *accessibilityPageControl;
@end
@implementation SMPageControl
{
@private
NSInteger _displayedPage;
CGFloat _measuredIndicatorWidth;
CGFloat _measuredIndicatorHeight;
CGImageRef _pageImageMask;
}
@synthesize pageNames = _pageNames;
@synthesize pageImages = _pageImages;
@synthesize currentPageImages = _currentPageImages;
@synthesize pageImageMasks = _pageImageMasks;
@synthesize cgImageMasks = _cgImageMasks;
+ (void)initialize
{
NSString *reqSysVer = @"7.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) {
_defaultStyleForSystemVersion = SMPageControlDefaultStyleModern;
} else {
_defaultStyleForSystemVersion = SMPageControlDefaultStyleClassic;
}
}
- (void)_initialize
{
_numberOfPages = 0;
_tapBehavior = SMPageControlTapBehaviorStep;
self.backgroundColor = [UIColor clearColor];
// If the app wasn't linked against iOS 7 or newer, always use the classic style
// otherwise, use the style of the current OS.
#ifdef __IPHONE_7_0
[self setStyleWithDefaults:_defaultStyleForSystemVersion];
#else
[self setStyleWithDefaults:SMPageControlDefaultStyleClassic];
#endif
_alignment = SMPageControlAlignmentCenter;
_verticalAlignment = SMPageControlVerticalAlignmentMiddle;
self.isAccessibilityElement = YES;
self.accessibilityTraits = UIAccessibilityTraitUpdatesFrequently;
self.accessibilityPageControl = [[UIPageControl alloc] init];
self.contentMode = UIViewContentModeRedraw;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (nil == self) {
return nil;
}
[self _initialize];
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (nil == self) {
return nil;
}
[self _initialize];
return self;
}
- (void)dealloc
{
if (_pageImageMask) {
CGImageRelease(_pageImageMask);
}
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[self _renderPages:context rect:rect];
}
- (void)_renderPages:(CGContextRef)context rect:(CGRect)rect
{
NSMutableArray *pageRects = [NSMutableArray arrayWithCapacity:self.numberOfPages];
if (_numberOfPages < 2 && _hidesForSinglePage) {
return;
}
CGFloat left = [self _leftOffset];
CGFloat xOffset = left;
CGFloat yOffset = 0.0f;
UIColor *fillColor = nil;
UIImage *image = nil;
CGImageRef maskingImage = nil;
CGSize maskSize = CGSizeZero;
for (NSInteger i = 0; i < _numberOfPages; i++) {
NSNumber *indexNumber = @(i);
if (i == _displayedPage) {
fillColor = _currentPageIndicatorTintColor ? _currentPageIndicatorTintColor : [UIColor whiteColor];
image = _currentPageImages[indexNumber];
if (nil == image) {
image = _currentPageIndicatorImage;
}
} else {
fillColor = _pageIndicatorTintColor ? _pageIndicatorTintColor : [[UIColor whiteColor] colorWithAlphaComponent:0.3f];
image = _pageImages[indexNumber];
if (nil == image) {
image = _pageIndicatorImage;
}
}
// If no finished images have been set, try a masking image
if (nil == image) {
maskingImage = (__bridge CGImageRef)_cgImageMasks[indexNumber];
UIImage *originalImage = _pageImageMasks[indexNumber];
maskSize = originalImage.size;
// If no per page mask is set, try for a global page mask!
if (nil == maskingImage) {
maskingImage = _pageImageMask;
maskSize = _pageIndicatorMaskImage.size;
}
}
[fillColor set];
CGRect indicatorRect;
if (image) {
yOffset = [self _topOffsetForHeight:image.size.height rect:rect];
CGFloat centeredXOffset = xOffset + floorf((_measuredIndicatorWidth - image.size.width) / 2.0f);
[image drawAtPoint:CGPointMake(centeredXOffset, yOffset)];
indicatorRect = CGRectMake(centeredXOffset, yOffset, image.size.width, image.size.height);
} else if (maskingImage) {
yOffset = [self _topOffsetForHeight:maskSize.height rect:rect];
CGFloat centeredXOffset = xOffset + floorf((_measuredIndicatorWidth - maskSize.width) / 2.0f);
indicatorRect = CGRectMake(centeredXOffset, yOffset, maskSize.width, maskSize.height);
CGContextDrawImage(context, indicatorRect, maskingImage);
} else {
yOffset = [self _topOffsetForHeight:_indicatorDiameter rect:rect];
CGFloat centeredXOffset = xOffset + floorf((_measuredIndicatorWidth - _indicatorDiameter) / 2.0f);
indicatorRect = CGRectMake(centeredXOffset, yOffset, _indicatorDiameter, _indicatorDiameter);
CGContextFillEllipseInRect(context, indicatorRect);
}
[pageRects addObject:[NSValue valueWithCGRect:indicatorRect]];
maskingImage = NULL;
xOffset += _measuredIndicatorWidth + _indicatorMargin;
}
self.pageRects = pageRects;
}
- (CGFloat)_leftOffset
{
CGRect rect = self.bounds;
CGSize size = [self sizeForNumberOfPages:self.numberOfPages];
CGFloat left = 0.0f;
switch (_alignment) {
case SMPageControlAlignmentCenter:
left = ceilf(CGRectGetMidX(rect) - (size.width / 2.0f));
break;
case SMPageControlAlignmentRight:
left = CGRectGetMaxX(rect) - size.width;
break;
default:
break;
}
return left;
}
- (CGFloat)_topOffsetForHeight:(CGFloat)height rect:(CGRect)rect
{
CGFloat top = 0.0f;
switch (_verticalAlignment) {
case SMPageControlVerticalAlignmentMiddle:
top = CGRectGetMidY(rect) - (height / 2.0f);
break;
case SMPageControlVerticalAlignmentBottom:
top = CGRectGetMaxY(rect) - height;
break;
default:
break;
}
return top;
}
- (void)updateCurrentPageDisplay
{
_displayedPage = _currentPage;
[self setNeedsDisplay];
}
- (CGSize)sizeForNumberOfPages:(NSInteger)pageCount
{
CGFloat marginSpace = MAX(0, pageCount - 1) * _indicatorMargin;
CGFloat indicatorSpace = pageCount * _measuredIndicatorWidth;
CGSize size = CGSizeMake(marginSpace + indicatorSpace, _measuredIndicatorHeight);
return size;
}
- (CGRect)rectForPageIndicator:(NSInteger)pageIndex
{
if (pageIndex < 0 || pageIndex >= _numberOfPages) {
return CGRectZero;
}
CGFloat left = [self _leftOffset];
CGSize size = [self sizeForNumberOfPages:pageIndex + 1];
CGRect rect = CGRectMake(left + size.width - _measuredIndicatorWidth, 0, _measuredIndicatorWidth, _measuredIndicatorWidth);
return rect;
}
- (void)_setImage:(UIImage *)image forPage:(NSInteger)pageIndex type:(SMPageControlImageType)type
{
if (pageIndex < 0 || pageIndex >= _numberOfPages) {
return;
}
NSMutableDictionary *dictionary = nil;
switch (type) {
case SMPageControlImageTypeCurrent:
dictionary = self.currentPageImages;
break;
case SMPageControlImageTypeNormal:
dictionary = self.pageImages;
break;
case SMPageControlImageTypeMask:
dictionary = self.pageImageMasks;
break;
default:
break;
}
if (image) {
dictionary[@(pageIndex)] = image;
} else {
[dictionary removeObjectForKey:@(pageIndex)];
}
}
- (void)setImage:(UIImage *)image forPage:(NSInteger)pageIndex
{
[self _setImage:image forPage:pageIndex type:SMPageControlImageTypeNormal];
[self _updateMeasuredIndicatorSizes];
}
- (void)setCurrentImage:(UIImage *)image forPage:(NSInteger)pageIndex
{
[self _setImage:image forPage:pageIndex type:SMPageControlImageTypeCurrent];;
[self _updateMeasuredIndicatorSizes];
}
- (void)setImageMask:(UIImage *)image forPage:(NSInteger)pageIndex
{
[self _setImage:image forPage:pageIndex type:SMPageControlImageTypeMask];
if (nil == image) {
[self.cgImageMasks removeObjectForKey:@(pageIndex)];
return;
}
CGImageRef maskImage = [self createMaskForImage:image];
if (maskImage) {
self.cgImageMasks[@(pageIndex)] = (__bridge id)maskImage;
CGImageRelease(maskImage);
[self _updateMeasuredIndicatorSizeWithSize:image.size];
[self setNeedsDisplay];
}
}
- (id)_imageForPage:(NSInteger)pageIndex type:(SMPageControlImageType)type
{
if (pageIndex < 0 || pageIndex >= _numberOfPages) {
return nil;
}
NSDictionary *dictionary = nil;
switch (type) {
case SMPageControlImageTypeCurrent:
dictionary = _currentPageImages;
break;
case SMPageControlImageTypeNormal:
dictionary = _pageImages;
break;
case SMPageControlImageTypeMask:
dictionary = _pageImageMasks;
break;
default:
break;
}
return dictionary[@(pageIndex)];
}
- (UIImage *)imageForPage:(NSInteger)pageIndex
{
return [self _imageForPage:pageIndex type:SMPageControlImageTypeNormal];
}
- (UIImage *)currentImageForPage:(NSInteger)pageIndex
{
return [self _imageForPage:pageIndex type:SMPageControlImageTypeCurrent];
}
- (UIImage *)imageMaskForPage:(NSInteger)pageIndex
{
return [self _imageForPage:pageIndex type:SMPageControlImageTypeMask];
}
- (CGSize)sizeThatFits:(CGSize)size
{
CGSize sizeThatFits = [self sizeForNumberOfPages:self.numberOfPages];
sizeThatFits.height = MAX(sizeThatFits.height, _minHeight);
return sizeThatFits;
}
- (CGSize)intrinsicContentSize
{
if (_numberOfPages < 1 || (_numberOfPages < 2 && _hidesForSinglePage)) {
return CGSizeMake(UIViewNoIntrinsicMetric, 0.0f);
}
CGSize intrinsicContentSize = CGSizeMake(UIViewNoIntrinsicMetric, MAX(_measuredIndicatorHeight, _minHeight));
return intrinsicContentSize;
}
- (void)updatePageNumberForScrollView:(UIScrollView *)scrollView
{
NSInteger page = (int)floorf(scrollView.contentOffset.x / scrollView.bounds.size.width);
self.currentPage = page;
}
- (void)setScrollViewContentOffsetForCurrentPage:(UIScrollView *)scrollView animated:(BOOL)animated
{
CGPoint offset = scrollView.contentOffset;
offset.x = scrollView.bounds.size.width * self.currentPage;
[scrollView setContentOffset:offset animated:animated];
}
- (void)setStyleWithDefaults:(SMPageControlStyleDefaults)defaultStyle
{
switch (defaultStyle) {
case SMPageControlDefaultStyleModern:
self.indicatorDiameter = DEFAULT_INDICATOR_WIDTH_LARGE;
self.indicatorMargin = DEFAULT_INDICATOR_MARGIN_LARGE;
self.pageIndicatorTintColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2f];
self.minHeight = DEFAULT_MIN_HEIGHT_LARGE;
break;
case SMPageControlDefaultStyleClassic:
default:
self.indicatorDiameter = DEFAULT_INDICATOR_WIDTH;
self.indicatorMargin = DEFAULT_INDICATOR_MARGIN;
self.pageIndicatorTintColor = [[UIColor whiteColor] colorWithAlphaComponent:0.3f];
self.minHeight = DEFAULT_MIN_HEIGHT;
break;
}
}
#pragma mark -
- (CGImageRef)createMaskForImage:(UIImage *)image CF_RETURNS_RETAINED
{
size_t pixelsWide = image.size.width * image.scale;
size_t pixelsHigh = image.size.height * image.scale;
size_t bitmapBytesPerRow = (pixelsWide * 1);
CGContextRef context = CGBitmapContextCreate(NULL, pixelsWide, pixelsHigh, CGImageGetBitsPerComponent(image.CGImage), bitmapBytesPerRow, NULL, (CGBitmapInfo)kCGImageAlphaOnly);
CGContextTranslateCTM(context, 0.f, pixelsHigh);
CGContextScaleCTM(context, 1.0f, -1.0f);
CGContextDrawImage(context, CGRectMake(0, 0, pixelsWide, pixelsHigh), image.CGImage);
CGImageRef maskImage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
return maskImage;
}
- (void)_updateMeasuredIndicatorSizeWithSize:(CGSize)size
{
_measuredIndicatorWidth = MAX(_measuredIndicatorWidth, size.width);
_measuredIndicatorHeight = MAX(_measuredIndicatorHeight, size.height);
}
- (void)_updateMeasuredIndicatorSizes
{
_measuredIndicatorWidth = _indicatorDiameter;
_measuredIndicatorHeight = _indicatorDiameter;
// If we're only using images, ignore the _indicatorDiameter
if ( (self.pageIndicatorImage || self.pageIndicatorMaskImage) && self.currentPageIndicatorImage )
{
_measuredIndicatorWidth = 0;
_measuredIndicatorHeight = 0;
}
if (self.pageIndicatorImage) {
[self _updateMeasuredIndicatorSizeWithSize:self.pageIndicatorImage.size];
}
if (self.currentPageIndicatorImage) {
[self _updateMeasuredIndicatorSizeWithSize:self.currentPageIndicatorImage.size];
}
if (self.pageIndicatorMaskImage) {
[self _updateMeasuredIndicatorSizeWithSize:self.pageIndicatorMaskImage.size];
}
if ([self respondsToSelector:@selector(invalidateIntrinsicContentSize)]) {
[self invalidateIntrinsicContentSize];
}
}
#pragma mark - Tap Gesture
// We're using touchesEnded: because we want to mimick UIPageControl as close as possible
// As of iOS 6, UIPageControl still (as far as we know) does not use a tap gesture recognizer. This means that actions like
// touching down, sliding around, and releasing, still results in the page incrementing or decrementing.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
if (SMPageControlTapBehaviorJump == self.tapBehavior) {
__block NSInteger tappedIndicatorIndex = NSNotFound;
[self.pageRects enumerateObjectsUsingBlock:^(NSValue *value, NSUInteger index, BOOL *stop) {
CGRect indicatorRect = [value CGRectValue];
if (CGRectContainsPoint(indicatorRect, point)) {
tappedIndicatorIndex = index;
*stop = YES;
}
}];
if (NSNotFound != tappedIndicatorIndex) {
[self setCurrentPage:tappedIndicatorIndex sendEvent:YES canDefer:YES];
return;
}
}
CGSize size = [self sizeForNumberOfPages:self.numberOfPages];
CGFloat left = [self _leftOffset];
CGFloat middle = left + (size.width / 2.0f);
if (point.x < middle) {
[self setCurrentPage:self.currentPage - 1 sendEvent:YES canDefer:YES];
} else {
[self setCurrentPage:self.currentPage + 1 sendEvent:YES canDefer:YES];
}
}
#pragma mark - Accessors
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
[self setNeedsDisplay];
}
- (void)setIndicatorDiameter:(CGFloat)indicatorDiameter
{
if (indicatorDiameter == _indicatorDiameter) {
return;
}
_indicatorDiameter = indicatorDiameter;
// Absolute minimum height of the control is the indicator diameter
if (_minHeight < indicatorDiameter) {
self.minHeight = indicatorDiameter;
}
[self _updateMeasuredIndicatorSizes];
[self setNeedsDisplay];
}
- (void)setIndicatorMargin:(CGFloat)indicatorMargin
{
if (indicatorMargin == _indicatorMargin) {
return;
}
_indicatorMargin = indicatorMargin;
[self setNeedsDisplay];
}
- (void)setMinHeight:(CGFloat)minHeight
{
if (minHeight == _minHeight) {
return;
}
// Absolute minimum height of the control is the indicator diameter
if (minHeight < _indicatorDiameter) {
minHeight = _indicatorDiameter;
}
_minHeight = minHeight;
if ([self respondsToSelector:@selector(invalidateIntrinsicContentSize)]) {
[self invalidateIntrinsicContentSize];
}
[self setNeedsLayout];
}
- (void)setNumberOfPages:(NSInteger)numberOfPages
{
[self setHidden:(numberOfPages<=1)];
if (numberOfPages == _numberOfPages) {
return;
}
self.accessibilityPageControl.numberOfPages = numberOfPages;
_numberOfPages = MAX(0, numberOfPages);
if ([self respondsToSelector:@selector(invalidateIntrinsicContentSize)]) {
[self invalidateIntrinsicContentSize];
}
[self updateAccessibilityValue];
[self setNeedsDisplay];
}
- (void)setCurrentPage:(NSInteger)currentPage
{
[self setCurrentPage:currentPage sendEvent:NO canDefer:NO];
}
- (void)setCurrentPage:(NSInteger)currentPage sendEvent:(BOOL)sendEvent canDefer:(BOOL)defer
{
_currentPage = MIN(MAX(0, currentPage), _numberOfPages - 1);
self.accessibilityPageControl.currentPage = self.currentPage;
[self updateAccessibilityValue];
if (NO == self.defersCurrentPageDisplay || NO == defer) {
_displayedPage = _currentPage;
[self setNeedsDisplay];
}
if (sendEvent) {
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
}
- (void)setCurrentPageIndicatorImage:(UIImage *)currentPageIndicatorImage
{
if ([currentPageIndicatorImage isEqual:_currentPageIndicatorImage]) {
return;
}
_currentPageIndicatorImage = currentPageIndicatorImage;
[self _updateMeasuredIndicatorSizes];
[self setNeedsDisplay];
}
- (void)setPageIndicatorImage:(UIImage *)pageIndicatorImage
{
if ([pageIndicatorImage isEqual:_pageIndicatorImage]) {
return;
}
_pageIndicatorImage = pageIndicatorImage;
[self _updateMeasuredIndicatorSizes];
[self setNeedsDisplay];
}
- (void)setPageIndicatorMaskImage:(UIImage *)pageIndicatorMaskImage
{
if ([pageIndicatorMaskImage isEqual:_pageIndicatorMaskImage]) {
return;
}
_pageIndicatorMaskImage = pageIndicatorMaskImage;
if (_pageImageMask) {
CGImageRelease(_pageImageMask);
}
_pageImageMask = [self createMaskForImage:_pageIndicatorMaskImage];
[self _updateMeasuredIndicatorSizes];
[self setNeedsDisplay];
}
- (NSMutableDictionary *)pageNames
{
if (nil != _pageNames) {
return _pageNames;
}
_pageNames = [[NSMutableDictionary alloc] init];
return _pageNames;
}
- (NSMutableDictionary *)pageImages
{
if (nil != _pageImages) {
return _pageImages;
}
_pageImages = [[NSMutableDictionary alloc] init];
return _pageImages;
}
- (NSMutableDictionary *)currentPageImages
{
if (nil != _currentPageImages) {
return _currentPageImages;
}
_currentPageImages = [[NSMutableDictionary alloc] init];
return _currentPageImages;
}
- (NSMutableDictionary *)pageImageMasks
{
if (nil != _pageImageMasks) {
return _pageImageMasks;
}
_pageImageMasks = [[NSMutableDictionary alloc] init];
return _pageImageMasks;
}
- (NSMutableDictionary *)cgImageMasks
{
if (nil != _cgImageMasks) {
return _cgImageMasks;
}
_cgImageMasks = [[NSMutableDictionary alloc] init];
return _cgImageMasks;
}
#pragma mark - UIAccessibility
- (void)setName:(NSString *)name forPage:(NSInteger)pageIndex
{
if (pageIndex < 0 || pageIndex >= _numberOfPages) {
return;
}
self.pageNames[@(pageIndex)] = name;
}
- (NSString *)nameForPage:(NSInteger)pageIndex
{
if (pageIndex < 0 || pageIndex >= _numberOfPages) {
return nil;
}
return self.pageNames[@(pageIndex)];
}
- (void)updateAccessibilityValue
{
NSString *pageName = [self nameForPage:self.currentPage];
NSString *accessibilityValue = self.accessibilityPageControl.accessibilityValue;
if (pageName) {
self.accessibilityValue = [NSString stringWithFormat:@"%@ - %@", pageName, accessibilityValue];
} else {
self.accessibilityValue = accessibilityValue;
}
}
@end