diff --git a/.gitignore b/.gitignore index ec58845f..51220252 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,5 @@ playground.xcworkspace Carthage/Build -.swift-version \ No newline at end of file +.swift-version +.swiftpm/xcode diff --git a/CHANGELOG.md b/CHANGELOG.md index 467ae876..8ed3ee77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to XLPagerTabStrip will be documented in this file. +### [9.1.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/9.1.0) + +* SPM support. + ### [9.0.0](https://github.com/xmartlabs/XLPagerTabStrip/releases/tag/9.0.0) * Xcode 10.2 and Swift 5.0 support. diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index c74467a3..51a001fa 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -563,7 +563,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = "$(SRCROOT)/Example/Example/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.Example; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -580,7 +580,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = "$(SRCROOT)/Example/Example/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.xmartlabs.Example; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Sources/FXPageControl.h b/ObjC/FXPageControl.h similarity index 70% rename from Sources/FXPageControl.h rename to ObjC/FXPageControl.h index 37a0438a..19ed5898 100755 --- a/Sources/FXPageControl.h +++ b/ObjC/FXPageControl.h @@ -1,7 +1,7 @@ // // FXPageControl.h // -// Version 1.4 +// Version 1.6 // // Created by Nick Lockwood on 07/01/2010. // Copyright 2010 Charcoal Design @@ -31,18 +31,12 @@ // -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wobjc-missing-property-synthesis" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-missing-property-synthesis" #import -#import -#undef weak_delegate -#if __has_feature(objc_arc_weak) -#define weak_delegate weak -#else -#define weak_delegate unsafe_unretained -#endif +NS_ASSUME_NONNULL_BEGIN extern const CGPathRef FXPageControlDotShapeCircle; @@ -59,7 +53,7 @@ IB_DESIGNABLE @interface FXPageControl : UIControl - (CGSize)sizeForNumberOfPages:(NSInteger)pageCount; - (void)updateCurrentPageDisplay; -@property (nonatomic, weak_delegate) IBOutlet id delegate; +@property (nonatomic, weak) IBOutlet id delegate; @property (nonatomic, assign) IBInspectable NSInteger currentPage; @property (nonatomic, assign) IBInspectable NSInteger numberOfPages; @@ -68,21 +62,25 @@ IB_DESIGNABLE @interface FXPageControl : UIControl @property (nonatomic, assign, getter = isWrapEnabled) IBInspectable BOOL wrapEnabled; @property (nonatomic, assign, getter = isVertical) IBInspectable BOOL vertical; -@property (nonatomic, strong) IBInspectable UIImage *dotImage; @property (nonatomic, assign) IBInspectable CGPathRef dotShape; @property (nonatomic, assign) IBInspectable CGFloat dotSize; -@property (nonatomic, strong) IBInspectable UIColor *dotColor; -@property (nonatomic, strong) IBInspectable UIColor *dotShadowColor; @property (nonatomic, assign) IBInspectable CGFloat dotShadowBlur; @property (nonatomic, assign) IBInspectable CGSize dotShadowOffset; +@property (nonatomic, assign) IBInspectable CGFloat dotBorderWidth; +@property (nonatomic, strong, nullable) IBInspectable UIImage *dotImage; +@property (nonatomic, strong, nullable) IBInspectable UIColor *dotColor; +@property (nonatomic, strong, nullable) IBInspectable UIColor *dotShadowColor; +@property (nonatomic, strong, nullable) IBInspectable UIColor *dotBorderColor; -@property (nonatomic, strong) IBInspectable UIImage *selectedDotImage; @property (nonatomic, assign) IBInspectable CGPathRef selectedDotShape; @property (nonatomic, assign) IBInspectable CGFloat selectedDotSize; -@property (nonatomic, strong) IBInspectable UIColor *selectedDotColor; -@property (nonatomic, strong) IBInspectable UIColor *selectedDotShadowColor; @property (nonatomic, assign) IBInspectable CGFloat selectedDotShadowBlur; @property (nonatomic, assign) IBInspectable CGSize selectedDotShadowOffset; +@property (nonatomic, assign) IBInspectable CGFloat selectedDotBorderWidth; +@property (nonatomic, strong, nullable) IBInspectable UIImage *selectedDotImage; +@property (nonatomic, strong, nullable) IBInspectable UIColor *selectedDotColor; +@property (nonatomic, strong, nullable) IBInspectable UIColor *selectedDotShadowColor; +@property (nonatomic, strong, nullable) IBInspectable UIColor *selectedDotBorderColor; @property (nonatomic, assign) IBInspectable CGFloat dotSpacing; @@ -92,15 +90,18 @@ IB_DESIGNABLE @interface FXPageControl : UIControl @protocol FXPageControlDelegate @optional -- (UIImage *)pageControl:(FXPageControl *)pageControl imageForDotAtIndex:(NSInteger)index; +- (nullable UIImage *)pageControl:(FXPageControl *)pageControl imageForDotAtIndex:(NSInteger)index; - (CGPathRef)pageControl:(FXPageControl *)pageControl shapeForDotAtIndex:(NSInteger)index; - (UIColor *)pageControl:(FXPageControl *)pageControl colorForDotAtIndex:(NSInteger)index; -- (UIImage *)pageControl:(FXPageControl *)pageControl selectedImageForDotAtIndex:(NSInteger)index; +- (nullable UIImage *)pageControl:(FXPageControl *)pageControl selectedImageForDotAtIndex:(NSInteger)index; - (CGPathRef)pageControl:(FXPageControl *)pageControl selectedShapeForDotAtIndex:(NSInteger)index; - (UIColor *)pageControl:(FXPageControl *)pageControl selectedColorForDotAtIndex:(NSInteger)index; @end -#pragma GCC diagnostic pop +NS_ASSUME_NONNULL_END + + +#pragma clang diagnostic pop diff --git a/Sources/FXPageControl.m b/ObjC/FXPageControl.m similarity index 50% rename from Sources/FXPageControl.m rename to ObjC/FXPageControl.m index 01602e8a..efc8d37c 100755 --- a/Sources/FXPageControl.m +++ b/ObjC/FXPageControl.m @@ -1,7 +1,7 @@ // // FXPageControl.m // -// Version 1.4 +// Version 1.6 // // Created by Nick Lockwood on 07/01/2010. // Copyright 2010 Charcoal Design @@ -33,9 +33,11 @@ #import "FXPageControl.h" -#pragma GCC diagnostic ignored "-Wgnu" -#pragma GCC diagnostic ignored "-Warc-repeated-use-of-weak" -#pragma GCC diagnostic ignored "-Wdirect-ivar-access" +#pragma clang diagnostic ignored "-Wgnu" +#pragma clang diagnostic ignored "-Wfloat-equal" +#pragma clang diagnostic ignored "-Wfloat-conversion" +#pragma clang diagnostic ignored "-Warc-repeated-use-of-weak" +#pragma clang diagnostic ignored "-Wdirect-ivar-access" #import @@ -50,49 +52,36 @@ #define LAST_SHAPE FXPageControlDotShapeTriangle -@implementation NSObject (FXPageControl) - -- (UIImage *)pageControl:(__unused FXPageControl *)pageControl imageForDotAtIndex:(__unused NSInteger)index { return nil; } -- (CGPathRef)pageControl:(__unused FXPageControl *)pageControl shapeForDotAtIndex:(__unused NSInteger)index { return NULL; } -- (UIColor *)pageControl:(__unused FXPageControl *)pageControl colorForDotAtIndex:(__unused NSInteger)index { return nil; } - -- (UIImage *)pageControl:(__unused FXPageControl *)pageControl selectedImageForDotAtIndex:(__unused NSInteger)index { return nil; } -- (CGPathRef)pageControl:(__unused FXPageControl *)pageControl selectedShapeForDotAtIndex:(__unused NSInteger)index { return NULL; } -- (UIColor *)pageControl:(__unused FXPageControl *)pageControl selectedColorForDotAtIndex:(__unused NSInteger)index { return nil; } - -@end - - @implementation FXPageControl - (void)setUp -{ +{ //needs redrawing if bounds change self.contentMode = UIViewContentModeRedraw; - - //set defaults - _dotSpacing = 10.0f; - _dotSize = 6.0f; + + //set defaults + _dotSpacing = 10.0; + _dotSize = 6.0; _dotShadowOffset = CGSizeMake(0, 1); _selectedDotShadowOffset = CGSizeMake(0, 1); } -- (id)initWithFrame:(CGRect)frame +- (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) - { - [self setUp]; + { + [self setUp]; } return self; } -- (id)initWithCoder:(NSCoder *)aDecoder +- (instancetype)initWithCoder:(NSCoder *)aDecoder { - if ((self = [super initWithCoder:aDecoder])) - { - [self setUp]; - } - return self; + if ((self = [super initWithCoder:aDecoder])) + { + [self setUp]; + } + return self; } - (void)dealloc @@ -112,11 +101,12 @@ - (void)updateCurrentPageDisplay [self setNeedsDisplay]; } -- (void)drawRect:(__unused CGRect)rect +- (void)drawRect:(CGRect)rect { - if (_numberOfPages > 1 || !_hidesForSinglePage) - { + if (_numberOfPages > 1 || !_hidesForSinglePage) + { CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextClearRect(context, rect); CGSize size = [self sizeForNumberOfPages:_numberOfPages]; if (_vertical) { @@ -126,93 +116,150 @@ - (void)drawRect:(__unused CGRect)rect { CGContextTranslateCTM(context, (self.frame.size.width - size.width) / 2, self.frame.size.height / 2); } - + for (int i = 0; i < _numberOfPages; i++) - { - UIImage *dotImage = nil; + { + UIImage *dotImage = nil; UIColor *dotColor = nil; CGPathRef dotShape = NULL; CGFloat dotSize = 0; UIColor *dotShadowColor = nil; CGSize dotShadowOffset = CGSizeZero; CGFloat dotShadowBlur = 0; - - if (i == _currentPage) - { - [_selectedDotColor setFill]; - dotImage = [_delegate pageControl:self selectedImageForDotAtIndex:i] ?: _selectedDotImage; - dotShape = [_delegate pageControl:self selectedShapeForDotAtIndex:i] ?: _selectedDotShape ?: _dotShape; - dotColor = [_delegate pageControl:self selectedColorForDotAtIndex:i] ?: _selectedDotColor ?: [UIColor blackColor]; + CGFloat dotBorderWidth = 0; + UIColor *dotBorderColor = nil; + + if (i == _currentPage) + { + if ([_delegate respondsToSelector:@selector(pageControl:selectedImageForDotAtIndex:)]) + { + dotImage = [_delegate pageControl:self selectedImageForDotAtIndex:i]; + } + else + { + dotImage = _selectedDotImage; + } + if ([_delegate respondsToSelector:@selector(pageControl:selectedShapeForDotAtIndex:)]) + { + dotShape = [_delegate pageControl:self selectedShapeForDotAtIndex:i]; + } + else + { + dotShape = _selectedDotShape ?: _dotShape; + } + if ([_delegate respondsToSelector:@selector(pageControl:selectedColorForDotAtIndex:)]) + { + dotColor = [_delegate pageControl:self selectedColorForDotAtIndex:i]; + } + else + { + dotColor = _selectedDotColor ?: [UIColor blackColor]; + } dotShadowBlur = _selectedDotShadowBlur; dotShadowColor = _selectedDotShadowColor; dotShadowOffset = _selectedDotShadowOffset; + dotBorderWidth = _selectedDotBorderWidth; + dotBorderColor = _selectedDotBorderColor; dotSize = _selectedDotSize ?: _dotSize; - } - else - { - [_dotColor setFill]; - dotImage = [_delegate pageControl:self imageForDotAtIndex:i] ?: _dotImage; - dotShape = [_delegate pageControl:self shapeForDotAtIndex:i] ?: _dotShape; - dotColor = [_delegate pageControl:self colorForDotAtIndex:i] ?: _dotColor; + } + else + { + if ([_delegate respondsToSelector:@selector(pageControl:imageForDotAtIndex:)]) + { + dotImage = [_delegate pageControl:self imageForDotAtIndex:i]; + } + else + { + dotImage = _dotImage; + } + if ([_delegate respondsToSelector:@selector(pageControl:shapeForDotAtIndex:)]) + { + dotShape = [_delegate pageControl:self shapeForDotAtIndex:i]; + } + else + { + dotShape = _dotShape; + } + if ([_delegate respondsToSelector:@selector(pageControl:colorForDotAtIndex:)]) + { + dotColor = [_delegate pageControl:self colorForDotAtIndex:i]; + } + else + { + dotColor = _dotColor; + } if (!dotColor) { //fall back to selected dot color with reduced alpha - dotColor = [_delegate pageControl:self selectedColorForDotAtIndex:i] ?: _selectedDotColor ?: [UIColor blackColor]; - dotColor = [dotColor colorWithAlphaComponent:0.25f]; + if ([_delegate respondsToSelector:@selector(pageControl:selectedColorForDotAtIndex:)]) + { + dotColor = [_delegate pageControl:self selectedColorForDotAtIndex:i]; + } + else + { + dotColor = _selectedDotColor ?: [UIColor blackColor]; + } + dotColor = [dotColor colorWithAlphaComponent:0.25]; } dotShadowBlur = _dotShadowBlur; dotShadowColor = _dotShadowColor; dotShadowOffset = _dotShadowOffset; + dotBorderWidth = _dotBorderWidth; + dotBorderColor = _dotBorderColor; dotSize = _dotSize; - } - + } + + [dotColor setFill]; + CGContextSaveGState(context); CGFloat offset = (_dotSize + _dotSpacing) * i + _dotSize / 2; CGContextTranslateCTM(context, _vertical? 0: offset, _vertical? offset: 0); - + if (dotShadowColor && ![dotShadowColor isEqual:[UIColor clearColor]]) { CGContextSetShadowWithColor(context, dotShadowOffset, dotShadowBlur, dotShadowColor.CGColor); } - if (dotImage) - { - [dotImage drawInRect:CGRectMake(-dotImage.size.width / 2, -dotImage.size.height / 2, dotImage.size.width, dotImage.size.height)]; - } - else - { - [dotColor setFill]; + if (dotImage) + { + [dotImage drawInRect:CGRectMake(-dotImage.size.width / 2, -dotImage.size.height / 2, dotImage.size.width, dotImage.size.height)]; + } + else + { + [dotBorderColor setStroke]; + CGContextSetLineWidth(context, dotBorderWidth); if (!dotShape || dotShape == FXPageControlDotShapeCircle) { - CGContextFillEllipseInRect(context, CGRectMake(-dotSize / 2, -dotSize / 2, dotSize, dotSize)); + CGContextAddEllipseInRect(context, CGRectMake(-dotSize / 2, -dotSize / 2, dotSize, dotSize)); } else if (dotShape == FXPageControlDotShapeSquare) { - CGContextFillRect(context, CGRectMake(-dotSize / 2, -dotSize / 2, dotSize, dotSize)); + CGContextAddRect(context, CGRectMake(-dotSize / 2, -dotSize / 2, dotSize, dotSize)); } else if (dotShape == FXPageControlDotShapeTriangle) { - CGContextBeginPath(context); CGContextMoveToPoint(context, 0, -dotSize / 2); CGContextAddLineToPoint(context, dotSize / 2, dotSize / 2); CGContextAddLineToPoint(context, -dotSize / 2, dotSize / 2); CGContextAddLineToPoint(context, 0, -dotSize / 2); - CGContextFillPath(context); } else { - CGContextBeginPath(context); CGContextAddPath(context, dotShape); - CGContextFillPath(context); } - } + + if (dotBorderWidth == 0) + CGContextDrawPath(context, kCGPathFill); + else + CGContextDrawPath(context, kCGPathFillStroke); + } CGContextRestoreGState(context); - } - } + } + } } - (NSInteger)clampedPageValue:(NSInteger)page { - if (_wrapEnabled) + if (_wrapEnabled) { return _numberOfPages? (page + _numberOfPages) % _numberOfPages: 0; } @@ -224,150 +271,193 @@ - (NSInteger)clampedPageValue:(NSInteger)page - (void)setDotImage:(UIImage *)dotImage { - if (_dotImage != dotImage) - { - _dotImage = dotImage; - [self setNeedsDisplay]; - } + if (_dotImage != dotImage) + { + _dotImage = dotImage; + [self setNeedsDisplay]; + } } - (void)setDotShape:(CGPathRef)dotShape { - if (_dotShape != dotShape) - { + if (_dotShape != dotShape) + { if (_dotShape > LAST_SHAPE) CGPathRelease(_dotShape); _dotShape = dotShape; if (_dotShape > LAST_SHAPE) CGPathRetain(_dotShape); - [self setNeedsDisplay]; - } + [self setNeedsDisplay]; + } } - (void)setDotSize:(CGFloat)dotSize { if (ABS(_dotSize - dotSize) > 0.001) - { - _dotSize = dotSize; - [self setNeedsDisplay]; - } + { + _dotSize = dotSize; + [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; + } } - (void)setDotColor:(UIColor *)dotColor { - if (_dotColor != dotColor) - { - _dotColor = dotColor; - [self setNeedsDisplay]; - } + if (_dotColor != dotColor) + { + _dotColor = dotColor; + [self setNeedsDisplay]; + } } - (void)setDotShadowColor:(UIColor *)dotColor { - if (_dotShadowColor != dotColor) - { - _dotShadowColor = dotColor; - [self setNeedsDisplay]; - } + if (_dotShadowColor != dotColor) + { + _dotShadowColor = dotColor; + [self setNeedsDisplay]; + } } - (void)setDotShadowBlur:(CGFloat)dotShadowBlur { - if (ABS(_dotShadowBlur - dotShadowBlur) > 0.001) - { - _dotShadowBlur = dotShadowBlur; - [self setNeedsDisplay]; - } + if (ABS(_dotShadowBlur - dotShadowBlur) > 0.001) + { + _dotShadowBlur = dotShadowBlur; + [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; + } } - (void)setDotShadowOffset:(CGSize)dotShadowOffset { - if (!CGSizeEqualToSize(_dotShadowOffset, dotShadowOffset)) - { - _dotShadowOffset = dotShadowOffset; - [self setNeedsDisplay]; - } + if (!CGSizeEqualToSize(_dotShadowOffset, dotShadowOffset)) + { + _dotShadowOffset = dotShadowOffset; + [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; + } +} + +- (void)setDotBorderWidth:(CGFloat)dotBorderWidth +{ + if (ABS(_dotBorderWidth - dotBorderWidth) > 0.001) + { + _dotBorderWidth = dotBorderWidth; + [self setNeedsDisplay]; + } +} + +- (void)setDotBorderColor:(UIColor *)dotBorderColor +{ + if (_dotBorderColor != dotBorderColor) + { + _dotBorderColor = dotBorderColor; + [self setNeedsDisplay]; + } } - (void)setSelectedDotImage:(UIImage *)dotImage { - if (_selectedDotImage != dotImage) - { - _selectedDotImage = dotImage; - [self setNeedsDisplay]; - } + if (_selectedDotImage != dotImage) + { + _selectedDotImage = dotImage; + [self setNeedsDisplay]; + } } - (void)setSelectedDotColor:(UIColor *)dotColor { - if (_selectedDotColor != dotColor) - { - _selectedDotColor = dotColor; - [self setNeedsDisplay]; - } + if (_selectedDotColor != dotColor) + { + _selectedDotColor = dotColor; + [self setNeedsDisplay]; + } } - (void)setSelectedDotShape:(CGPathRef)dotShape { - if (_selectedDotShape != dotShape) - { + if (_selectedDotShape != dotShape) + { if (_selectedDotShape > LAST_SHAPE) CGPathRelease(_selectedDotShape); _selectedDotShape = dotShape; if (_selectedDotShape > LAST_SHAPE) CGPathRetain(_selectedDotShape); - [self setNeedsDisplay]; - } + [self setNeedsDisplay]; + } } - (void)setSelectedDotSize:(CGFloat)dotSize { if (ABS(_selectedDotSize - dotSize) > 0.001) - { - _selectedDotSize = dotSize; - [self setNeedsDisplay]; - } + { + _selectedDotSize = dotSize; + [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; + } } - (void)setSelectedDotShadowColor:(UIColor *)dotColor { - if (_selectedDotShadowColor != dotColor) - { - _selectedDotShadowColor = dotColor; - [self setNeedsDisplay]; - } + if (_selectedDotShadowColor != dotColor) + { + _selectedDotShadowColor = dotColor; + [self setNeedsDisplay]; + } } - (void)setSelectedDotShadowBlur:(CGFloat)dotShadowBlur { if (ABS(_selectedDotShadowBlur - dotShadowBlur) > 0.001) - { - _selectedDotShadowBlur = dotShadowBlur; - [self setNeedsDisplay]; - } + { + _selectedDotShadowBlur = dotShadowBlur; + [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; + } } - (void)setSelectedDotShadowOffset:(CGSize)dotShadowOffset { - if (!CGSizeEqualToSize(_selectedDotShadowOffset, dotShadowOffset)) - { - _selectedDotShadowOffset = dotShadowOffset; - [self setNeedsDisplay]; - } + if (!CGSizeEqualToSize(_selectedDotShadowOffset, dotShadowOffset)) + { + _selectedDotShadowOffset = dotShadowOffset; + [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; + } +} + +- (void)setSelectedDotBorderWidth:(CGFloat)selectedDotBorderWidth +{ + if (ABS(_selectedDotBorderWidth - selectedDotBorderWidth) > 0.001) + { + _selectedDotBorderWidth = selectedDotBorderWidth; + [self setNeedsDisplay]; + } +} + +- (void)setSelectedDotBorderColor:(UIColor *)dotColor +{ + if (_selectedDotBorderColor != dotColor) + { + _selectedDotBorderColor = dotColor; + [self setNeedsDisplay]; + } } - (void)setDotSpacing:(CGFloat)dotSpacing { if (ABS(_dotSpacing - dotSpacing) > 0.001) - { - _dotSpacing = dotSpacing; - [self setNeedsDisplay]; - } + { + _dotSpacing = dotSpacing; + [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; + } } - (void)setDelegate:(id)delegate { - if (_delegate != delegate) - { - _delegate = delegate; - [self setNeedsDisplay]; - } + if (_delegate != delegate) + { + _delegate = delegate; + [self setNeedsDisplay]; + } } - (void)setCurrentPage:(NSInteger)page @@ -378,7 +468,7 @@ - (void)setCurrentPage:(NSInteger)page - (void)setNumberOfPages:(NSInteger)pages { - if (_numberOfPages != pages) + if (_numberOfPages != pages) { _numberOfPages = pages; if (_currentPage >= pages) @@ -386,20 +476,21 @@ - (void)setNumberOfPages:(NSInteger)pages _currentPage = pages - 1; } [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; } } - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { - CGPoint point = [touch locationInView:self]; + CGPoint point = [touch locationInView:self]; BOOL forward = _vertical? (point.y > self.frame.size.height / 2): (point.x > self.frame.size.width / 2); - _currentPage = [self clampedPageValue:_currentPage + (forward? 1: -1)]; + _currentPage = [self clampedPageValue:_currentPage + (forward? 1: -1)]; if (!_defersCurrentPageDisplay) { [self setNeedsDisplay]; } - [self sendActionsForControlEvents:UIControlEventValueChanged]; - [super endTrackingWithTouch:touch withEvent:event]; + [self sendActionsForControlEvents:UIControlEventValueChanged]; + [super endTrackingWithTouch:touch withEvent:event]; } - (CGSize)sizeThatFits:(__unused CGSize)size @@ -429,4 +520,23 @@ - (CGSize)intrinsicContentSize return [self sizeThatFits:self.bounds.size]; } +#pragma mark - Accessibility + +- (UIAccessibilityTraits)accessibilityTraits +{ + return UIAccessibilityTraitAdjustable; +} + +- (void)accessibilityIncrement +{ + self.currentPage = self.currentPage + 1; + [self sendActionsForControlEvents:UIControlEventValueChanged]; +} + +- (void)accessibilityDecrement +{ + self.currentPage = self.currentPage - 1; + [self sendActionsForControlEvents:UIControlEventValueChanged]; +} + @end diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 00000000..37d2f990 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "FXPageControl", + "repositoryURL": "https://github.com/nicklockwood/FXPageControl.git", + "state": { + "branch": null, + "revision": "a94633402ba98c52f86c2a70e61ff086dec9de78", + "version": "1.6.0" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..a858ceec --- /dev/null +++ b/Package.swift @@ -0,0 +1,31 @@ +// swift-tools-version: 5.4 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "XLPagerTabStrip", + platforms: [ + .iOS(.v11) + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "XLPagerTabStrip", + targets: ["XLPagerTabStrip"]), + ], + dependencies: [ + .package( + url: "https://github.com/nicklockwood/FXPageControl.git", + .upToNextMajor(from: "1.6.0") + ) + ], + targets: [ + .target( + name: "XLPagerTabStrip", + dependencies: ["FXPageControl"]), + ], + swiftLanguageVersions: [ + .v5 + ] +) diff --git a/README.md b/README.md index e3cc9926..280fdf50 100644 --- a/README.md +++ b/README.md @@ -320,6 +320,12 @@ To install XLPagerTabStrip, simply add the following line to your Cartfile: github "xmartlabs/XLPagerTabStrip" ~> 9.0 ``` +### SPM + +- File > Swift Packages > Add Package Dependency +- Add `https://github.com/xmartlabs/XLPagerTabStrip.git` +- Select "Up to Next Major" with "9.0.0" + ## FAQ #### How to change the visible child view controller programmatically diff --git a/Sources/BarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/BarPagerTabStripViewController.swift similarity index 100% rename from Sources/BarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/BarPagerTabStripViewController.swift diff --git a/Sources/BarView.swift b/Sources/XLPagerTabStrip/BarView.swift similarity index 99% rename from Sources/BarView.swift rename to Sources/XLPagerTabStrip/BarView.swift index 1183524d..843b8bc3 100644 --- a/Sources/BarView.swift +++ b/Sources/XLPagerTabStrip/BarView.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit open class BarView: UIView { diff --git a/Sources/BaseButtonBarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift similarity index 99% rename from Sources/BaseButtonBarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift index 68684ac4..cbdde5a9 100644 --- a/Sources/BaseButtonBarPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/BaseButtonBarPagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit open class BaseButtonBarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource { @@ -322,7 +323,12 @@ open class ExampleBaseButtonBarPagerTabStripViewController: BaseButtonBarPagerTa } open func initialize() { + #if SWIFT_PACKAGE + var bundle = Bundle.module + #else var bundle = Bundle(for: ButtonBarViewCell.self) + #endif + if let resourcePath = bundle.path(forResource: "XLPagerTabStrip", ofType: "bundle") { if let resourcesBundle = Bundle(path: resourcePath) { bundle = resourcesBundle diff --git a/Sources/ButtonBarPagerTabStripViewController.swift b/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift similarity index 99% rename from Sources/ButtonBarPagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift index 36e008d6..46464ca9 100644 --- a/Sources/ButtonBarPagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/ButtonBarPagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit public enum ButtonBarItemSpec { @@ -94,7 +95,12 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa open override func viewDidLoad() { super.viewDidLoad() + #if SWIFT_PACKAGE + var bundle = Bundle.module + #else var bundle = Bundle(for: ButtonBarViewCell.self) + #endif + if let resourcePath = bundle.path(forResource: "XLPagerTabStrip", ofType: "bundle") { if let resourcesBundle = Bundle(path: resourcePath) { bundle = resourcesBundle diff --git a/Sources/ButtonBarView.swift b/Sources/XLPagerTabStrip/ButtonBarView.swift similarity index 100% rename from Sources/ButtonBarView.swift rename to Sources/XLPagerTabStrip/ButtonBarView.swift diff --git a/Sources/ButtonBarViewCell.swift b/Sources/XLPagerTabStrip/ButtonBarViewCell.swift similarity index 100% rename from Sources/ButtonBarViewCell.swift rename to Sources/XLPagerTabStrip/ButtonBarViewCell.swift diff --git a/Sources/IndicatorInfo.swift b/Sources/XLPagerTabStrip/IndicatorInfo.swift similarity index 99% rename from Sources/IndicatorInfo.swift rename to Sources/XLPagerTabStrip/IndicatorInfo.swift index 146eb9a5..e5fff108 100644 --- a/Sources/IndicatorInfo.swift +++ b/Sources/XLPagerTabStrip/IndicatorInfo.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit public struct IndicatorInfo { diff --git a/Sources/PagerTabStripBehaviour.swift b/Sources/XLPagerTabStrip/PagerTabStripBehaviour.swift similarity index 100% rename from Sources/PagerTabStripBehaviour.swift rename to Sources/XLPagerTabStrip/PagerTabStripBehaviour.swift diff --git a/Sources/PagerTabStripError.swift b/Sources/XLPagerTabStrip/PagerTabStripError.swift similarity index 100% rename from Sources/PagerTabStripError.swift rename to Sources/XLPagerTabStrip/PagerTabStripError.swift diff --git a/Sources/PagerTabStripViewController.swift b/Sources/XLPagerTabStrip/PagerTabStripViewController.swift similarity index 99% rename from Sources/PagerTabStripViewController.swift rename to Sources/XLPagerTabStrip/PagerTabStripViewController.swift index 9aedb7d6..781a3136 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/XLPagerTabStrip/PagerTabStripViewController.swift @@ -23,6 +23,7 @@ // THE SOFTWARE. import Foundation +import UIKit // MARK: Protocols @@ -32,7 +33,7 @@ public protocol IndicatorInfoProvider { } -public protocol PagerTabStripDelegate: class { +public protocol PagerTabStripDelegate: AnyObject { func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int) } @@ -42,7 +43,7 @@ public protocol PagerTabStripIsProgressiveDelegate: PagerTabStripDelegate { func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) } -public protocol PagerTabStripDataSource: class { +public protocol PagerTabStripDataSource: AnyObject { func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] } diff --git a/Sources/ButtonCell.xib b/Sources/XLPagerTabStrip/Resources/ButtonCell.xib similarity index 87% rename from Sources/ButtonCell.xib rename to Sources/XLPagerTabStrip/Resources/ButtonCell.xib index 7025bc70..d8f15e54 100644 --- a/Sources/ButtonCell.xib +++ b/Sources/XLPagerTabStrip/Resources/ButtonCell.xib @@ -1,17 +1,15 @@ - - - - + + - + - + @@ -19,7 +17,7 @@