Merge pull request #32 from diegosanchezr/master
Renames BMACircle* -> Circle*
This commit is contained in:
commit
cbe74fcffa
|
|
@ -474,7 +474,7 @@
|
|||
buildSettings = {
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.BMAChatFrameworkTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
|
|
@ -484,7 +484,7 @@
|
|||
buildSettings = {
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.BMAChatFrameworkTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
|
|
|
|||
|
|
@ -60,12 +60,12 @@
|
|||
C3C0CC621BFE496A0052747C /* TextChatInputItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC191BFE496A0052747C /* TextChatInputItem.swift */; };
|
||||
C3C0CC631BFE496A0052747C /* KeyedOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC1A1BFE496A0052747C /* KeyedOperationQueue.swift */; };
|
||||
C3C0CC641BFE496A0052747C /* Observable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC1B1BFE496A0052747C /* Observable.swift */; };
|
||||
C3C0CC661BFE496A0052747C /* BMACircleIconView.h in Headers */ = {isa = PBXBuildFile; fileRef = C3C0CC1F1BFE496A0052747C /* BMACircleIconView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
C3C0CC671BFE496A0052747C /* BMACircleIconView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC201BFE496A0052747C /* BMACircleIconView.m */; };
|
||||
C3C0CC681BFE496A0052747C /* BMACircleProgressIndicatorView.h in Headers */ = {isa = PBXBuildFile; fileRef = C3C0CC211BFE496A0052747C /* BMACircleProgressIndicatorView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
C3C0CC691BFE496A0052747C /* BMACircleProgressIndicatorView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC221BFE496A0052747C /* BMACircleProgressIndicatorView.m */; };
|
||||
C3C0CC6A1BFE496A0052747C /* BMACircleProgressView.h in Headers */ = {isa = PBXBuildFile; fileRef = C3C0CC231BFE496A0052747C /* BMACircleProgressView.h */; };
|
||||
C3C0CC6B1BFE496A0052747C /* BMACircleProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC241BFE496A0052747C /* BMACircleProgressView.m */; };
|
||||
C3C0CC661BFE496A0052747C /* CircleIconView.h in Headers */ = {isa = PBXBuildFile; fileRef = C3C0CC1F1BFE496A0052747C /* CircleIconView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
C3C0CC671BFE496A0052747C /* CircleIconView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC201BFE496A0052747C /* CircleIconView.m */; };
|
||||
C3C0CC681BFE496A0052747C /* CircleProgressIndicatorView.h in Headers */ = {isa = PBXBuildFile; fileRef = C3C0CC211BFE496A0052747C /* CircleProgressIndicatorView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
C3C0CC691BFE496A0052747C /* CircleProgressIndicatorView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC221BFE496A0052747C /* CircleProgressIndicatorView.m */; };
|
||||
C3C0CC6A1BFE496A0052747C /* CircleProgressView.h in Headers */ = {isa = PBXBuildFile; fileRef = C3C0CC231BFE496A0052747C /* CircleProgressView.h */; };
|
||||
C3C0CC6B1BFE496A0052747C /* CircleProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC241BFE496A0052747C /* CircleProgressView.m */; };
|
||||
C3C0CC6C1BFE496A0052747C /* CircleProgressIndicator.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3C0CC251BFE496A0052747C /* CircleProgressIndicator.xcassets */; };
|
||||
C3C0CC851BFE49700052747C /* ChatInputBarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC771BFE49700052747C /* ChatInputBarTests.swift */; };
|
||||
C3C0CC861BFE49700052747C /* ChatInputItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC781BFE49700052747C /* ChatInputItemTests.swift */; };
|
||||
|
|
@ -145,12 +145,12 @@
|
|||
C3C0CC191BFE496A0052747C /* TextChatInputItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextChatInputItem.swift; sourceTree = "<group>"; };
|
||||
C3C0CC1A1BFE496A0052747C /* KeyedOperationQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyedOperationQueue.swift; sourceTree = "<group>"; };
|
||||
C3C0CC1B1BFE496A0052747C /* Observable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Observable.swift; sourceTree = "<group>"; };
|
||||
C3C0CC1F1BFE496A0052747C /* BMACircleIconView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMACircleIconView.h; sourceTree = "<group>"; };
|
||||
C3C0CC201BFE496A0052747C /* BMACircleIconView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BMACircleIconView.m; sourceTree = "<group>"; };
|
||||
C3C0CC211BFE496A0052747C /* BMACircleProgressIndicatorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMACircleProgressIndicatorView.h; sourceTree = "<group>"; };
|
||||
C3C0CC221BFE496A0052747C /* BMACircleProgressIndicatorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BMACircleProgressIndicatorView.m; sourceTree = "<group>"; };
|
||||
C3C0CC231BFE496A0052747C /* BMACircleProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BMACircleProgressView.h; sourceTree = "<group>"; };
|
||||
C3C0CC241BFE496A0052747C /* BMACircleProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BMACircleProgressView.m; sourceTree = "<group>"; };
|
||||
C3C0CC1F1BFE496A0052747C /* CircleIconView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CircleIconView.h; sourceTree = "<group>"; };
|
||||
C3C0CC201BFE496A0052747C /* CircleIconView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CircleIconView.m; sourceTree = "<group>"; };
|
||||
C3C0CC211BFE496A0052747C /* CircleProgressIndicatorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CircleProgressIndicatorView.h; sourceTree = "<group>"; };
|
||||
C3C0CC221BFE496A0052747C /* CircleProgressIndicatorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CircleProgressIndicatorView.m; sourceTree = "<group>"; };
|
||||
C3C0CC231BFE496A0052747C /* CircleProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CircleProgressView.h; sourceTree = "<group>"; };
|
||||
C3C0CC241BFE496A0052747C /* CircleProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CircleProgressView.m; sourceTree = "<group>"; };
|
||||
C3C0CC251BFE496A0052747C /* CircleProgressIndicator.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = CircleProgressIndicator.xcassets; sourceTree = "<group>"; };
|
||||
C3C0CC751BFE49700052747C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
C3C0CC771BFE49700052747C /* ChatInputBarTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatInputBarTests.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -372,12 +372,12 @@
|
|||
C3C0CC1E1BFE496A0052747C /* CircleProgressIndicatorView */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C3C0CC1F1BFE496A0052747C /* BMACircleIconView.h */,
|
||||
C3C0CC201BFE496A0052747C /* BMACircleIconView.m */,
|
||||
C3C0CC211BFE496A0052747C /* BMACircleProgressIndicatorView.h */,
|
||||
C3C0CC221BFE496A0052747C /* BMACircleProgressIndicatorView.m */,
|
||||
C3C0CC231BFE496A0052747C /* BMACircleProgressView.h */,
|
||||
C3C0CC241BFE496A0052747C /* BMACircleProgressView.m */,
|
||||
C3C0CC1F1BFE496A0052747C /* CircleIconView.h */,
|
||||
C3C0CC201BFE496A0052747C /* CircleIconView.m */,
|
||||
C3C0CC211BFE496A0052747C /* CircleProgressIndicatorView.h */,
|
||||
C3C0CC221BFE496A0052747C /* CircleProgressIndicatorView.m */,
|
||||
C3C0CC231BFE496A0052747C /* CircleProgressView.h */,
|
||||
C3C0CC241BFE496A0052747C /* CircleProgressView.m */,
|
||||
C3C0CC251BFE496A0052747C /* CircleProgressIndicator.xcassets */,
|
||||
);
|
||||
path = CircleProgressIndicatorView;
|
||||
|
|
@ -434,10 +434,10 @@
|
|||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C3C0CC6A1BFE496A0052747C /* BMACircleProgressView.h in Headers */,
|
||||
C3C0CC661BFE496A0052747C /* BMACircleIconView.h in Headers */,
|
||||
C3C0CC6A1BFE496A0052747C /* CircleProgressView.h in Headers */,
|
||||
C3C0CC661BFE496A0052747C /* CircleIconView.h in Headers */,
|
||||
C36F9C4B1BFE4A89001E9D8F /* ChattoAdditions.h in Headers */,
|
||||
C3C0CC681BFE496A0052747C /* BMACircleProgressIndicatorView.h in Headers */,
|
||||
C3C0CC681BFE496A0052747C /* CircleProgressIndicatorView.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
@ -570,7 +570,7 @@
|
|||
C3C0CC571BFE496A0052747C /* LiveCameraCell.swift in Sources */,
|
||||
C3C0CC591BFE496A0052747C /* PhotosChatInputItem.swift in Sources */,
|
||||
C3C0CC3A1BFE496A0052747C /* PhotoMessageCollectionViewCell.swift in Sources */,
|
||||
C3C0CC691BFE496A0052747C /* BMACircleProgressIndicatorView.m in Sources */,
|
||||
C3C0CC691BFE496A0052747C /* CircleProgressIndicatorView.m in Sources */,
|
||||
C3C0CC5D1BFE496A0052747C /* PhotosInputDataProvider.swift in Sources */,
|
||||
C3C0CC5C1BFE496A0052747C /* PhotosInputCellProvider.swift in Sources */,
|
||||
C3C0CC3C1BFE496A0052747C /* TextMessageModel.swift in Sources */,
|
||||
|
|
@ -596,13 +596,13 @@
|
|||
C3C0CC2E1BFE496A0052747C /* BaseMessageCollectionViewCell.swift in Sources */,
|
||||
C3C0CC5A1BFE496A0052747C /* PhotosInputCameraPicker.swift in Sources */,
|
||||
C3C0CC551BFE496A0052747C /* ExpandableTextView.swift in Sources */,
|
||||
C3C0CC6B1BFE496A0052747C /* BMACircleProgressView.m in Sources */,
|
||||
C3C0CC6B1BFE496A0052747C /* CircleProgressView.m in Sources */,
|
||||
C3C0CC371BFE496A0052747C /* PhotoMessageViewModel.swift in Sources */,
|
||||
C3C0CC2F1BFE496A0052747C /* BaseMessageCollectionViewCellDefaultSyle.swift in Sources */,
|
||||
C3C0CC5B1BFE496A0052747C /* PhotosInputCell.swift in Sources */,
|
||||
C3C0CC561BFE496A0052747C /* HorizontalStackScrollView.swift in Sources */,
|
||||
C3C0CC5F1BFE496A0052747C /* PhotosInputViewItemSizeCalculator.swift in Sources */,
|
||||
C3C0CC671BFE496A0052747C /* BMACircleIconView.m in Sources */,
|
||||
C3C0CC671BFE496A0052747C /* CircleIconView.m in Sources */,
|
||||
C3C0CC301BFE496A0052747C /* ViewDefinitions.swift in Sources */,
|
||||
C3C0CC531BFE496A0052747C /* ChatInputItem.swift in Sources */,
|
||||
C3C0CC421BFE496A0052747C /* TextMessageCollectionViewCell.swift in Sources */,
|
||||
|
|
@ -741,7 +741,7 @@
|
|||
INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.BMAChatFrameworkAdditions;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoAdditions;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
|
|
@ -757,7 +757,7 @@
|
|||
INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.BMAChatFrameworkAdditions;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoAdditions;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
|
|
@ -768,7 +768,7 @@
|
|||
buildSettings = {
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.BMAChatFrameworkAdditionsTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoAdditionsTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
|
|
@ -778,7 +778,7 @@
|
|||
buildSettings = {
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.BMAChatFrameworkAdditionsTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.badoo.ChattoAdditionsTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ public final class PhotoBubbleView: UIView, MaximumLayoutWidthSpecificable, Back
|
|||
|
||||
|
||||
|
||||
private var progressIndicatorView: BMACircleProgressIndicatorView = {
|
||||
let progressView = BMACircleProgressIndicatorView(size: CGSize(width: 33, height: 33))
|
||||
private var progressIndicatorView: CircleProgressIndicatorView = {
|
||||
let progressView = CircleProgressIndicatorView(size: CGSize(width: 33, height: 33))
|
||||
return progressView
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -32,4 +32,4 @@ FOUNDATION_EXPORT const unsigned char ChattoAdditionsVersionString[];
|
|||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <Chatto/PublicHeader.h>
|
||||
|
||||
#import "BMACircleProgressIndicatorView.h"
|
||||
#import "CircleProgressIndicatorView.h"
|
||||
|
|
|
|||
|
|
@ -1,276 +0,0 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present Badoo Trading Limited.
|
||||
|
||||
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 "BMACircleIconView.h"
|
||||
|
||||
struct BMACircleProgressIconPoints {
|
||||
CGPoint bma_top;
|
||||
CGPoint bma_centre;
|
||||
CGPoint bma_bottom;
|
||||
CGPoint bma_left;
|
||||
CGPoint bma_right;
|
||||
};
|
||||
|
||||
@interface BMACircleIconView ()
|
||||
@property (nonatomic) BMACircleIconType type;
|
||||
|
||||
@property (nonatomic, strong) UIImageView *iconView;
|
||||
@property (nonatomic, strong) UILabel *titleView;
|
||||
|
||||
@property (nonatomic, strong) CAShapeLayer *iconLayer;
|
||||
@property (nonatomic, assign) struct BMACircleProgressIconPoints iconPoints;
|
||||
|
||||
@property (nonatomic, assign) CGFloat lineWidth;
|
||||
@property (nonatomic, strong) UIColor *lineColor;
|
||||
@end
|
||||
|
||||
@implementation BMACircleIconView
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)commonInit {
|
||||
[self initIconLayer];
|
||||
[self initIconView];
|
||||
[self initTitleView];
|
||||
}
|
||||
|
||||
- (void)initIconLayer {
|
||||
self.iconLayer = [CAShapeLayer layer];
|
||||
_iconLayer.strokeColor = _lineColor.CGColor;
|
||||
_iconLayer.fillColor = nil;
|
||||
_iconLayer.lineCap = kCALineCapRound;
|
||||
_iconLayer.lineWidth = _lineWidth;
|
||||
_iconLayer.fillRule = kCAFillRuleNonZero;
|
||||
[self.layer addSublayer:_iconLayer];
|
||||
}
|
||||
|
||||
- (void)initIconView {
|
||||
self.iconView = [[UIImageView alloc] initWithFrame:self.bounds];
|
||||
self.iconView.contentMode = UIViewContentModeCenter;
|
||||
[self addSubview:self.iconView];
|
||||
}
|
||||
|
||||
- (void)initTitleView {
|
||||
self.titleView = [[UILabel alloc] initWithFrame:self.bounds];
|
||||
self.titleView.textAlignment = NSTextAlignmentCenter;
|
||||
// FIXME
|
||||
// self.titleView.font = [BMANewConnectionsUIDevFeature isAvailable] ? [BMAStyleSheet fontForTypeStyle:BMATypeStyleBodySmallNormal] : [UIFont systemFontOfSize:12];
|
||||
[self addSubview:self.titleView];
|
||||
}
|
||||
|
||||
#pragma mark - iconLayer
|
||||
|
||||
- (void)setupIconLayerWithType:(BMACircleIconType)type {
|
||||
[self setupIconPointsWithType:type];
|
||||
switch (type) {
|
||||
case BMACircleIconTypeArrowUp:
|
||||
[self drawArrowPointingTo:self.iconPoints.bma_top];
|
||||
break;
|
||||
case BMACircleIconTypeArrowDown:
|
||||
[self drawArrowPointingTo:self.iconPoints.bma_bottom];
|
||||
break;
|
||||
case BMACircleIconTypeStop:
|
||||
[self drawStop];
|
||||
break;
|
||||
default:
|
||||
_iconLayer.path = nil;
|
||||
_iconLayer.fillColor = nil;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupIconPointsWithType:(BMACircleIconType)type {
|
||||
struct BMACircleProgressIconPoints points = {};
|
||||
points.bma_centre = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
|
||||
points.bma_bottom = CGPointMake(points.bma_centre.x, points.bma_centre.y + (self.outterCircleRadius - self.verticalMargin));
|
||||
points.bma_top = CGPointMake(points.bma_centre.x, points.bma_centre.y - (self.outterCircleRadius - self.verticalMargin));
|
||||
|
||||
switch (type) {
|
||||
case BMACircleIconTypeArrowDown:
|
||||
points.bma_left = CGPointMake(points.bma_centre.x - (self.outterCircleRadius - self.horizontalMargin), points.bma_centre.y);
|
||||
points.bma_right = CGPointMake(points.bma_centre.x + (self.outterCircleRadius - self.horizontalMargin), points.bma_centre.y);
|
||||
break;
|
||||
case BMACircleIconTypeArrowUp:
|
||||
points.bma_left = CGPointMake(points.bma_centre.x - (self.outterCircleRadius - self.horizontalMargin), points.bma_centre.y);
|
||||
points.bma_right = CGPointMake(points.bma_centre.x + (self.outterCircleRadius - self.horizontalMargin), points.bma_centre.y);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
self.iconPoints = points;
|
||||
}
|
||||
|
||||
- (void)drawArrowPointingTo:(CGPoint)point {
|
||||
UIBezierPath *path = [UIBezierPath bezierPath];
|
||||
[path moveToPoint:self.iconPoints.bma_left];
|
||||
[path addLineToPoint:point];
|
||||
[path closePath];
|
||||
|
||||
[path moveToPoint:point];
|
||||
[path addLineToPoint:self.iconPoints.bma_right];
|
||||
[path closePath];
|
||||
|
||||
[path moveToPoint:self.iconPoints.bma_top];
|
||||
[path addLineToPoint:self.iconPoints.bma_centre];
|
||||
[path addLineToPoint:self.iconPoints.bma_bottom];
|
||||
[path closePath];
|
||||
|
||||
_iconLayer.lineWidth = _lineWidth;
|
||||
_iconLayer.lineCap = kCALineCapRound;
|
||||
[_iconLayer setPath:path.CGPath];
|
||||
[_iconLayer setStrokeColor:self.lineColor.CGColor];
|
||||
[_iconLayer setFillColor:nil];
|
||||
}
|
||||
|
||||
- (void)drawStop {
|
||||
CGFloat radius = (self.bounds.size.width) / 2;
|
||||
UIBezierPath *stopPath = [UIBezierPath bezierPath];
|
||||
[stopPath moveToPoint:CGPointMake(0, 0)];
|
||||
[stopPath addLineToPoint:CGPointMake(self.horizontalMargin, 0.0)];
|
||||
[stopPath addLineToPoint:CGPointMake(self.horizontalMargin, self.horizontalMargin)];
|
||||
[stopPath addLineToPoint:CGPointMake(0.0, self.horizontalMargin)];
|
||||
[stopPath closePath];
|
||||
[stopPath applyTransform:CGAffineTransformMakeTranslation(radius * (1 - self.horizontalMarginCoef), radius * (1 - self.horizontalMarginCoef))];
|
||||
|
||||
[_iconLayer setPath:stopPath.CGPath];
|
||||
[_iconLayer setStrokeColor:self.lineColor.CGColor];
|
||||
[_iconLayer setFillColor:self.lineColor.CGColor];
|
||||
}
|
||||
|
||||
#pragma mark - icon view
|
||||
|
||||
- (void)setupIconViewWithType:(BMACircleIconType)type {
|
||||
NSString *imageName = nil;
|
||||
switch (type) {
|
||||
case BMACircleIconTypeInfinity:
|
||||
imageName = @"infinity_icon_norm";
|
||||
break;
|
||||
case BMACircleIconTypeExclamation:
|
||||
imageName = @"warning_icon_norm";
|
||||
break;
|
||||
case BMACircleIconTypeCheck:
|
||||
imageName = @"tick_viewed_icon_norm";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (imageName) {
|
||||
self.iconView.image = [UIImage imageNamed:imageName inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - icon view
|
||||
|
||||
- (void)setupVisibilityWithType:(BMACircleIconType)type {
|
||||
self.titleView.hidden = YES;
|
||||
self.iconLayer.hidden = YES;
|
||||
self.iconView.hidden = YES;
|
||||
|
||||
switch (type) {
|
||||
case BMACircleIconTypeInfinity:
|
||||
case BMACircleIconTypeExclamation:
|
||||
case BMACircleIconTypeCheck:
|
||||
self.iconView.hidden = NO;
|
||||
break;
|
||||
case BMACircleIconTypeArrowDown:
|
||||
case BMACircleIconTypeArrowUp:
|
||||
case BMACircleIconTypeStop:
|
||||
self.iconLayer.hidden = NO;
|
||||
break;
|
||||
case BMACircleIconTypeText:
|
||||
self.titleView.hidden = NO;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - life cycle
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
_iconLayer.frame = self.bounds;
|
||||
}
|
||||
|
||||
#pragma mark - actions
|
||||
|
||||
- (void)setType:(BMACircleIconType)type {
|
||||
_type = type;
|
||||
[self setupVisibilityWithType:_type];
|
||||
|
||||
[self setupIconLayerWithType:_type];
|
||||
[self setupIconViewWithType:_type];
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSAttributedString *)title {
|
||||
[self setType:BMACircleIconTypeText];
|
||||
self.titleView.attributedText = title;
|
||||
}
|
||||
|
||||
- (void)setLineColor:(UIColor *)lineColor {
|
||||
_lineColor = lineColor;
|
||||
_iconLayer.strokeColor = lineColor.CGColor;
|
||||
_titleView.textColor = lineColor;
|
||||
}
|
||||
|
||||
- (void)setLineWidth:(CGFloat)lineWidth {
|
||||
_lineWidth = lineWidth;
|
||||
_iconLayer.lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
#pragma mark - defaults
|
||||
|
||||
- (CGFloat)verticalMargin {
|
||||
return self.bounds.size.width * 0.28;
|
||||
}
|
||||
|
||||
- (CGFloat)horizontalMargin {
|
||||
return self.bounds.size.width * 0.29;
|
||||
}
|
||||
|
||||
- (CGFloat)outterCircleRadius {
|
||||
return (self.bounds.size.width - 2 * _lineWidth) / 2;
|
||||
}
|
||||
|
||||
- (CGFloat)horizontalMarginCoef {
|
||||
return 0.28;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,235 +0,0 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present Badoo Trading Limited.
|
||||
|
||||
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 "BMACircleProgressIndicatorView.h"
|
||||
#import "BMACircleProgressView.h"
|
||||
|
||||
@interface BMACircleProgressIndicatorView ()
|
||||
@property (nonatomic, assign) BOOL supportsCancel;
|
||||
@property (nonatomic, strong) UIGestureRecognizer *stopLoadingTap;
|
||||
|
||||
@property (nonatomic, assign) CGFloat progress;
|
||||
|
||||
@property (nonatomic, strong) BMACircleProgressView *progressView;
|
||||
@property (nonatomic, strong) BMACircleIconView *circleIconView;
|
||||
@end
|
||||
|
||||
@implementation BMACircleProgressIndicatorView
|
||||
|
||||
+ (instancetype)defaultProgressIndicatorView {
|
||||
BMACircleProgressIndicatorView *view = [[BMACircleProgressIndicatorView alloc] initWithFrame:CGRectMake(.0f, .0f, 28.0f, 28.0f)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
return view;
|
||||
}
|
||||
|
||||
+ (instancetype)progressIndicatorViewWithSize:(CGSize)size {
|
||||
BMACircleProgressIndicatorView *view = [[BMACircleProgressIndicatorView alloc] initWithFrame:CGRectMake(.0f, .0f, size.width, size.height)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
return view;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)commonInit {
|
||||
_progressLineColor = [self defaultLineColor];
|
||||
_progressLineWidth = [self defaultLineWidth];
|
||||
|
||||
_progressView = [[BMACircleProgressView alloc] initWithFrame:self.bounds];
|
||||
[_progressView setLineColor:[self defaultLineColor]];
|
||||
[_progressView setLineWidth:[self defaultLineWidth]];
|
||||
[self addSubview:_progressView];
|
||||
|
||||
_circleIconView = [[BMACircleIconView alloc] initWithFrame:self.bounds];
|
||||
[_circleIconView setLineColor:[self defaultLineColor]];
|
||||
[_circleIconView setLineWidth:[self defaultLineWidth]];
|
||||
[self addSubview:_circleIconView];
|
||||
}
|
||||
|
||||
#pragma mark - stop gesture recognizer
|
||||
|
||||
- (void)addStopGestureRecognizer {
|
||||
if (self.stopLoadingTap) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.stopLoadingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stopLoadingTapped)];
|
||||
[self addGestureRecognizer:self.stopLoadingTap];
|
||||
}
|
||||
|
||||
- (void)removeStopGestureRecognizer {
|
||||
if (self.stopLoadingTap) {
|
||||
[self removeGestureRecognizer:self.stopLoadingTap];
|
||||
self.stopLoadingTap = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)stopLoadingTapped {
|
||||
[self removeStopGestureRecognizer];
|
||||
}
|
||||
|
||||
#pragma mark - Animations
|
||||
|
||||
- (void)prepareForLoading {
|
||||
[self removeStopGestureRecognizer];
|
||||
[self.progressView prepareForLoading];
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setProgressType:(BMACircleProgressType)progressType {
|
||||
_progressType = progressType;
|
||||
[self updateIconViewType];
|
||||
}
|
||||
|
||||
- (void)setProgressStatus:(BMACircleProgressStatus)progressStatus {
|
||||
_progressStatus = progressStatus;
|
||||
|
||||
[self.progressView finishPrepareForLoading];
|
||||
[self.progressView setLineColor:self.progressLineColor];
|
||||
[self setProgressType:_progressType];
|
||||
|
||||
switch (_progressStatus) {
|
||||
case BMACircleProgressStatusFailed:
|
||||
[self.progressView setLineColor:[UIColor clearColor]];
|
||||
break;
|
||||
case BMACircleProgressStatusStarting:
|
||||
[self prepareForLoading];
|
||||
break;
|
||||
case BMACircleProgressStatusInProgress:
|
||||
if (self.supportsCancel) {
|
||||
[self addStopGestureRecognizer];
|
||||
}
|
||||
break;
|
||||
case BMACircleProgressStatusCompleted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateIconViewType {
|
||||
switch (_progressType) {
|
||||
case BMACircleProgressTypeUndefined:
|
||||
case BMACircleProgressTypeIcon:
|
||||
case BMACircleProgressTypeTimer:
|
||||
[self.circleIconView setType:BMACircleIconTypeText];
|
||||
break;
|
||||
case BMACircleProgressTypeUpload:
|
||||
[self.circleIconView setType:BMACircleIconTypeArrowUp];
|
||||
break;
|
||||
case BMACircleProgressTypeDownload:
|
||||
[self.circleIconView setType:BMACircleIconTypeArrowDown];
|
||||
break;
|
||||
}
|
||||
|
||||
switch (_progressStatus) {
|
||||
case BMACircleProgressStatusFailed:
|
||||
[self.circleIconView setType:BMACircleIconTypeExclamation];
|
||||
break;
|
||||
case BMACircleProgressStatusInProgress:
|
||||
if (self.supportsCancel) {
|
||||
[self.circleIconView setType:BMACircleIconTypeStop];
|
||||
}
|
||||
break;
|
||||
case BMACircleProgressStatusCompleted:
|
||||
[self.circleIconView setType:BMACircleIconTypeCheck];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setProgress:(CGFloat)progress {
|
||||
if (progress > 1.0) {
|
||||
progress = 1.0;
|
||||
}
|
||||
|
||||
if (_progress != progress) {
|
||||
_progress = progress;
|
||||
[self.progressView setProgress:progress];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTimerTitle:(NSAttributedString *)title {
|
||||
[self setProgressType:BMACircleProgressTypeTimer];
|
||||
[self.circleIconView setTitle:title];
|
||||
}
|
||||
|
||||
- (void)setTextTitle:(NSAttributedString *)title {
|
||||
[self setProgressType:BMACircleProgressTypeIcon];
|
||||
[self.circleIconView setTitle:title];
|
||||
}
|
||||
|
||||
- (void)setIconType:(BMACircleIconType)type {
|
||||
[self.circleIconView setType:type];
|
||||
}
|
||||
|
||||
#pragma mark - Default Settings
|
||||
|
||||
- (UIColor *)defaultLineColor {
|
||||
return [UIColor colorWithRed:0 green:0.47 blue:1 alpha:1.0];
|
||||
}
|
||||
|
||||
- (UIColor *)defaultRedLineColor {
|
||||
return [UIColor colorWithRed:0.92 green:0.18 blue:0.18 alpha:1.0];
|
||||
}
|
||||
|
||||
- (CGFloat)defaultLineWidth {
|
||||
return fmaxf(self.frame.size.width * 0.01, 1.02f);
|
||||
}
|
||||
|
||||
- (void)setProgressLineColor:(UIColor *)color {
|
||||
_progressLineColor = color;
|
||||
[self.progressView setLineColor:color];
|
||||
[self updateViews];
|
||||
|
||||
}
|
||||
- (void)setProgressLineWidth:(CGFloat)width {
|
||||
_progressLineWidth = width;
|
||||
[self.progressView setLineWidth:width];
|
||||
[self updateViews];
|
||||
}
|
||||
|
||||
- (void)updateViews {
|
||||
[self setProgressStatus:self.progressStatus];
|
||||
[self setProgressType:self.progressType];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present Badoo Trading Limited.
|
||||
|
||||
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 "BMACircleProgressView.h"
|
||||
|
||||
@interface BMACircleProgressView ()
|
||||
@property (nonatomic, assign) CGFloat lineWidth;
|
||||
@property (nonatomic, strong) UIColor *lineColor;
|
||||
@property (nonatomic, strong) CAShapeLayer *bgLayer;
|
||||
@property (nonatomic, strong) CAShapeLayer *progressLayer;
|
||||
@property (nonatomic, assign, getter=isPreparingForLoading) BOOL preparingForLoading;
|
||||
@property (nonatomic, assign) CGFloat progress;
|
||||
@end
|
||||
|
||||
@implementation BMACircleProgressView
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)commonInit {
|
||||
[self addSubLayers];
|
||||
[self updateBgLayer];
|
||||
}
|
||||
|
||||
#pragma mark - layers
|
||||
|
||||
- (void)addSubLayers {
|
||||
[self addBgLayer];
|
||||
[self addProgressLayer];
|
||||
}
|
||||
|
||||
- (void)addBgLayer {
|
||||
self.bgLayer = [CAShapeLayer layer];
|
||||
_bgLayer.strokeColor = _lineColor.CGColor;
|
||||
_bgLayer.fillColor = self.backgroundColor.CGColor;
|
||||
_bgLayer.lineCap = kCALineCapRound;
|
||||
_bgLayer.lineWidth = _lineWidth;
|
||||
[self.layer addSublayer:_bgLayer];
|
||||
}
|
||||
|
||||
- (void)addProgressLayer {
|
||||
self.progressLayer = [CAShapeLayer layer];
|
||||
_progressLayer.strokeColor = _lineColor.CGColor;
|
||||
_progressLayer.fillColor = nil;
|
||||
_progressLayer.lineCap = kCALineCapSquare;
|
||||
_progressLayer.lineWidth = _lineWidth * 2.2;
|
||||
[self.layer addSublayer:_progressLayer];
|
||||
}
|
||||
|
||||
#pragma mark - life cycle
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
_bgLayer.frame = self.bounds;
|
||||
_progressLayer.frame = self.bounds;
|
||||
}
|
||||
|
||||
#pragma mark - actions
|
||||
|
||||
- (void)prepareForLoading {
|
||||
self.preparingForLoading = YES;
|
||||
[self updateBgLayer];
|
||||
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
|
||||
rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
|
||||
rotationAnimation.duration = 1;
|
||||
rotationAnimation.cumulative = YES;
|
||||
rotationAnimation.repeatCount = HUGE_VALF;
|
||||
[_bgLayer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
|
||||
}
|
||||
|
||||
- (void)finishPrepareForLoading {
|
||||
if (self.preparingForLoading) {
|
||||
[_bgLayer removeAllAnimations];
|
||||
self.preparingForLoading = NO;
|
||||
[self updateBgLayer];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setProgress:(CGFloat)progress {
|
||||
if (progress >= 0.0 && progress <= 1.0) {
|
||||
_progress = progress;
|
||||
_progressLayer.hidden = _progress >= 1.0;
|
||||
[self updateProgressLayer];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - line style
|
||||
|
||||
- (void)setLineColor:(UIColor *)lineColor {
|
||||
_lineColor = lineColor;
|
||||
_bgLayer.strokeColor = lineColor.CGColor;
|
||||
_progressLayer.strokeColor = lineColor.CGColor;
|
||||
[self updateBgLayer];
|
||||
}
|
||||
|
||||
- (void)setLineWidth:(CGFloat)lineWidth {
|
||||
_lineWidth = lineWidth;
|
||||
_bgLayer.lineWidth = lineWidth;
|
||||
_progressLayer.lineWidth = lineWidth * 2.0;
|
||||
[self updateBgLayer];
|
||||
}
|
||||
|
||||
#pragma mark - Update Layers
|
||||
|
||||
- (void)updateBgLayer {
|
||||
CGFloat spinningGapInCircle = self.isPreparingForLoading ? 1.8 : 2.0;
|
||||
CGFloat radius = CGRectGetWidth(self.bounds) / 2 - self.lineWidth;
|
||||
CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
|
||||
UIBezierPath *bgCircle = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:-M_PI_2 endAngle:(spinningGapInCircle * M_PI - M_PI_2)clockwise:YES];
|
||||
bgCircle.lineWidth = _lineWidth;
|
||||
bgCircle.lineCapStyle = kCGLineCapRound;
|
||||
_bgLayer.path = bgCircle.CGPath;
|
||||
}
|
||||
|
||||
- (void)updateProgressLayer {
|
||||
CGFloat radius = (self.bounds.size.width - _lineWidth * 4) / 2.0;
|
||||
CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
|
||||
UIBezierPath *progressCircle = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:-M_PI_2 endAngle:self.progress * 2 * M_PI - M_PI_2 clockwise:YES];
|
||||
progressCircle.lineCapStyle = kCGLineCapButt;
|
||||
progressCircle.lineWidth = _lineWidth;
|
||||
_progressLayer.path = progressCircle.CGPath;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -24,22 +24,22 @@
|
|||
|
||||
@import UIKit;
|
||||
|
||||
typedef NS_ENUM(NSUInteger, BMACircleIconType) {
|
||||
BMACircleIconTypeUndefined,
|
||||
typedef NS_ENUM(NSUInteger, CircleIconType) {
|
||||
CircleIconTypeUndefined,
|
||||
|
||||
BMACircleIconTypeInfinity,
|
||||
BMACircleIconTypeExclamation,
|
||||
BMACircleIconTypeCheck,
|
||||
CircleIconTypeInfinity,
|
||||
CircleIconTypeExclamation,
|
||||
CircleIconTypeCheck,
|
||||
|
||||
BMACircleIconTypeArrowDown,
|
||||
BMACircleIconTypeArrowUp,
|
||||
BMACircleIconTypeStop,
|
||||
CircleIconTypeArrowDown,
|
||||
CircleIconTypeArrowUp,
|
||||
CircleIconTypeStop,
|
||||
|
||||
BMACircleIconTypeText
|
||||
CircleIconTypeText
|
||||
};
|
||||
|
||||
@interface BMACircleIconView : UIView
|
||||
- (void)setType:(BMACircleIconType)type;
|
||||
@interface CircleIconView : UIView
|
||||
- (void)setType:(CircleIconType)type;
|
||||
- (void)setTitle:(NSAttributedString *)title;
|
||||
|
||||
- (void)setLineWidth:(CGFloat)lineWidth;
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present Badoo Trading Limited.
|
||||
|
||||
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 "CircleIconView.h"
|
||||
|
||||
struct CircleProgressIconPoints {
|
||||
CGPoint bma_top;
|
||||
CGPoint bma_centre;
|
||||
CGPoint bma_bottom;
|
||||
CGPoint bma_left;
|
||||
CGPoint bma_right;
|
||||
};
|
||||
|
||||
@interface CircleIconView ()
|
||||
@property(nonatomic) CircleIconType type;
|
||||
|
||||
@property(nonatomic, strong) UIImageView *iconView;
|
||||
@property(nonatomic, strong) UILabel *titleView;
|
||||
|
||||
@property(nonatomic, strong) CAShapeLayer *iconLayer;
|
||||
@property(nonatomic, assign) struct CircleProgressIconPoints iconPoints;
|
||||
|
||||
@property(nonatomic, assign) CGFloat lineWidth;
|
||||
@property(nonatomic, strong) UIColor *lineColor;
|
||||
@end
|
||||
|
||||
@implementation CircleIconView
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)commonInit {
|
||||
[self initIconLayer];
|
||||
[self initIconView];
|
||||
[self initTitleView];
|
||||
}
|
||||
|
||||
- (void)initIconLayer {
|
||||
self.iconLayer = [CAShapeLayer layer];
|
||||
_iconLayer.strokeColor = _lineColor.CGColor;
|
||||
_iconLayer.fillColor = nil;
|
||||
_iconLayer.lineCap = kCALineCapRound;
|
||||
_iconLayer.lineWidth = _lineWidth;
|
||||
_iconLayer.fillRule = kCAFillRuleNonZero;
|
||||
[self.layer addSublayer:_iconLayer];
|
||||
}
|
||||
|
||||
- (void)initIconView {
|
||||
self.iconView = [[UIImageView alloc] initWithFrame:self.bounds];
|
||||
self.iconView.contentMode = UIViewContentModeCenter;
|
||||
[self addSubview:self.iconView];
|
||||
}
|
||||
|
||||
- (void)initTitleView {
|
||||
self.titleView = [[UILabel alloc] initWithFrame:self.bounds];
|
||||
self.titleView.textAlignment = NSTextAlignmentCenter;
|
||||
// FIXME
|
||||
// self.titleView.font = [NewConnectionsUIDevFeature isAvailable] ?
|
||||
// [StyleSheet fontForTypeStyle:TypeStyleBodySmallNormal] : [UIFont
|
||||
// systemFontOfSize:12];
|
||||
[self addSubview:self.titleView];
|
||||
}
|
||||
|
||||
#pragma mark - iconLayer
|
||||
|
||||
- (void)setupIconLayerWithType:(CircleIconType)type {
|
||||
[self setupIconPointsWithType:type];
|
||||
switch (type) {
|
||||
case CircleIconTypeArrowUp:
|
||||
[self drawArrowPointingTo:self.iconPoints.bma_top];
|
||||
break;
|
||||
case CircleIconTypeArrowDown:
|
||||
[self drawArrowPointingTo:self.iconPoints.bma_bottom];
|
||||
break;
|
||||
case CircleIconTypeStop:
|
||||
[self drawStop];
|
||||
break;
|
||||
default:
|
||||
_iconLayer.path = nil;
|
||||
_iconLayer.fillColor = nil;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupIconPointsWithType:(CircleIconType)type {
|
||||
struct CircleProgressIconPoints points = {};
|
||||
points.bma_centre =
|
||||
CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
|
||||
points.bma_bottom = CGPointMake(
|
||||
points.bma_centre.x,
|
||||
points.bma_centre.y + (self.outterCircleRadius - self.verticalMargin));
|
||||
points.bma_top = CGPointMake(
|
||||
points.bma_centre.x,
|
||||
points.bma_centre.y - (self.outterCircleRadius - self.verticalMargin));
|
||||
|
||||
switch (type) {
|
||||
case CircleIconTypeArrowDown:
|
||||
points.bma_left = CGPointMake(
|
||||
points.bma_centre.x - (self.outterCircleRadius - self.horizontalMargin),
|
||||
points.bma_centre.y);
|
||||
points.bma_right = CGPointMake(
|
||||
points.bma_centre.x + (self.outterCircleRadius - self.horizontalMargin),
|
||||
points.bma_centre.y);
|
||||
break;
|
||||
case CircleIconTypeArrowUp:
|
||||
points.bma_left = CGPointMake(
|
||||
points.bma_centre.x - (self.outterCircleRadius - self.horizontalMargin),
|
||||
points.bma_centre.y);
|
||||
points.bma_right = CGPointMake(
|
||||
points.bma_centre.x + (self.outterCircleRadius - self.horizontalMargin),
|
||||
points.bma_centre.y);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
self.iconPoints = points;
|
||||
}
|
||||
|
||||
- (void)drawArrowPointingTo:(CGPoint)point {
|
||||
UIBezierPath *path = [UIBezierPath bezierPath];
|
||||
[path moveToPoint:self.iconPoints.bma_left];
|
||||
[path addLineToPoint:point];
|
||||
[path closePath];
|
||||
|
||||
[path moveToPoint:point];
|
||||
[path addLineToPoint:self.iconPoints.bma_right];
|
||||
[path closePath];
|
||||
|
||||
[path moveToPoint:self.iconPoints.bma_top];
|
||||
[path addLineToPoint:self.iconPoints.bma_centre];
|
||||
[path addLineToPoint:self.iconPoints.bma_bottom];
|
||||
[path closePath];
|
||||
|
||||
_iconLayer.lineWidth = _lineWidth;
|
||||
_iconLayer.lineCap = kCALineCapRound;
|
||||
[_iconLayer setPath:path.CGPath];
|
||||
[_iconLayer setStrokeColor:self.lineColor.CGColor];
|
||||
[_iconLayer setFillColor:nil];
|
||||
}
|
||||
|
||||
- (void)drawStop {
|
||||
CGFloat radius = (self.bounds.size.width) / 2;
|
||||
UIBezierPath *stopPath = [UIBezierPath bezierPath];
|
||||
[stopPath moveToPoint:CGPointMake(0, 0)];
|
||||
[stopPath addLineToPoint:CGPointMake(self.horizontalMargin, 0.0)];
|
||||
[stopPath
|
||||
addLineToPoint:CGPointMake(self.horizontalMargin, self.horizontalMargin)];
|
||||
[stopPath addLineToPoint:CGPointMake(0.0, self.horizontalMargin)];
|
||||
[stopPath closePath];
|
||||
[stopPath applyTransform:CGAffineTransformMakeTranslation(
|
||||
radius * (1 - self.horizontalMarginCoef),
|
||||
radius * (1 - self.horizontalMarginCoef))];
|
||||
|
||||
[_iconLayer setPath:stopPath.CGPath];
|
||||
[_iconLayer setStrokeColor:self.lineColor.CGColor];
|
||||
[_iconLayer setFillColor:self.lineColor.CGColor];
|
||||
}
|
||||
|
||||
#pragma mark - icon view
|
||||
|
||||
- (void)setupIconViewWithType:(CircleIconType)type {
|
||||
NSString *imageName = nil;
|
||||
switch (type) {
|
||||
case CircleIconTypeInfinity:
|
||||
imageName = @"infinity_icon_norm";
|
||||
break;
|
||||
case CircleIconTypeExclamation:
|
||||
imageName = @"warning_icon_norm";
|
||||
break;
|
||||
case CircleIconTypeCheck:
|
||||
imageName = @"tick_viewed_icon_norm";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (imageName) {
|
||||
self.iconView.image =
|
||||
[UIImage imageNamed:imageName
|
||||
inBundle:[NSBundle bundleForClass:[self class]]
|
||||
compatibleWithTraitCollection:nil];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - icon view
|
||||
|
||||
- (void)setupVisibilityWithType:(CircleIconType)type {
|
||||
self.titleView.hidden = YES;
|
||||
self.iconLayer.hidden = YES;
|
||||
self.iconView.hidden = YES;
|
||||
|
||||
switch (type) {
|
||||
case CircleIconTypeInfinity:
|
||||
case CircleIconTypeExclamation:
|
||||
case CircleIconTypeCheck:
|
||||
self.iconView.hidden = NO;
|
||||
break;
|
||||
case CircleIconTypeArrowDown:
|
||||
case CircleIconTypeArrowUp:
|
||||
case CircleIconTypeStop:
|
||||
self.iconLayer.hidden = NO;
|
||||
break;
|
||||
case CircleIconTypeText:
|
||||
self.titleView.hidden = NO;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - life cycle
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
_iconLayer.frame = self.bounds;
|
||||
}
|
||||
|
||||
#pragma mark - actions
|
||||
|
||||
- (void)setType:(CircleIconType)type {
|
||||
_type = type;
|
||||
[self setupVisibilityWithType:_type];
|
||||
|
||||
[self setupIconLayerWithType:_type];
|
||||
[self setupIconViewWithType:_type];
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSAttributedString *)title {
|
||||
[self setType:CircleIconTypeText];
|
||||
self.titleView.attributedText = title;
|
||||
}
|
||||
|
||||
- (void)setLineColor:(UIColor *)lineColor {
|
||||
_lineColor = lineColor;
|
||||
_iconLayer.strokeColor = lineColor.CGColor;
|
||||
_titleView.textColor = lineColor;
|
||||
}
|
||||
|
||||
- (void)setLineWidth:(CGFloat)lineWidth {
|
||||
_lineWidth = lineWidth;
|
||||
_iconLayer.lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
#pragma mark - defaults
|
||||
|
||||
- (CGFloat)verticalMargin {
|
||||
return self.bounds.size.width * 0.28;
|
||||
}
|
||||
|
||||
- (CGFloat)horizontalMargin {
|
||||
return self.bounds.size.width * 0.29;
|
||||
}
|
||||
|
||||
- (CGFloat)outterCircleRadius {
|
||||
return (self.bounds.size.width - 2 * _lineWidth) / 2;
|
||||
}
|
||||
|
||||
- (CGFloat)horizontalMarginCoef {
|
||||
return 0.28;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -23,30 +23,30 @@
|
|||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "BMACircleIconView.h"
|
||||
#import "CircleIconView.h"
|
||||
|
||||
typedef NS_ENUM(NSUInteger, BMACircleProgressType) {
|
||||
BMACircleProgressTypeUndefined,
|
||||
BMACircleProgressTypeIcon,
|
||||
BMACircleProgressTypeTimer,
|
||||
BMACircleProgressTypeUpload,
|
||||
BMACircleProgressTypeDownload,
|
||||
typedef NS_ENUM(NSUInteger, CircleProgressType) {
|
||||
CircleProgressTypeUndefined,
|
||||
CircleProgressTypeIcon,
|
||||
CircleProgressTypeTimer,
|
||||
CircleProgressTypeUpload,
|
||||
CircleProgressTypeDownload,
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSUInteger, BMACircleProgressStatus) {
|
||||
BMACircleProgressStatusUndefined,
|
||||
BMACircleProgressStatusStarting,
|
||||
BMACircleProgressStatusInProgress,
|
||||
BMACircleProgressStatusCompleted,
|
||||
BMACircleProgressStatusFailed,
|
||||
typedef NS_ENUM(NSUInteger, CircleProgressStatus) {
|
||||
CircleProgressStatusUndefined,
|
||||
CircleProgressStatusStarting,
|
||||
CircleProgressStatusInProgress,
|
||||
CircleProgressStatusCompleted,
|
||||
CircleProgressStatusFailed,
|
||||
};
|
||||
|
||||
@interface BMACircleProgressIndicatorView : UIView
|
||||
@interface CircleProgressIndicatorView : UIView
|
||||
|
||||
@property (nonatomic) BMACircleProgressType progressType;
|
||||
@property (nonatomic) BMACircleProgressStatus progressStatus;
|
||||
@property (nonatomic, strong) UIColor *progressLineColor;
|
||||
@property (nonatomic, assign) CGFloat progressLineWidth;
|
||||
@property(nonatomic) CircleProgressType progressType;
|
||||
@property(nonatomic) CircleProgressStatus progressStatus;
|
||||
@property(nonatomic, strong) UIColor *progressLineColor;
|
||||
@property(nonatomic, assign) CGFloat progressLineWidth;
|
||||
|
||||
+ (instancetype)defaultProgressIndicatorView;
|
||||
+ (instancetype)progressIndicatorViewWithSize:(CGSize)size;
|
||||
|
|
@ -54,8 +54,7 @@ typedef NS_ENUM(NSUInteger, BMACircleProgressStatus) {
|
|||
- (void)setProgress:(CGFloat)progress;
|
||||
- (void)setTimerTitle:(NSAttributedString *)title;
|
||||
- (void)setTextTitle:(NSAttributedString *)title;
|
||||
- (void)setIconType:(BMACircleIconType)type;
|
||||
- (void)setIconType:(CircleIconType)type;
|
||||
- (void)setSupportsCancel:(BOOL)supportsCancel;
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present Badoo Trading Limited.
|
||||
|
||||
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 "CircleProgressIndicatorView.h"
|
||||
#import "CircleProgressView.h"
|
||||
|
||||
@interface CircleProgressIndicatorView ()
|
||||
@property(nonatomic, assign) BOOL supportsCancel;
|
||||
@property(nonatomic, strong) UIGestureRecognizer *stopLoadingTap;
|
||||
|
||||
@property(nonatomic, assign) CGFloat progress;
|
||||
|
||||
@property(nonatomic, strong) CircleProgressView *progressView;
|
||||
@property(nonatomic, strong) CircleIconView *circleIconView;
|
||||
@end
|
||||
|
||||
@implementation CircleProgressIndicatorView
|
||||
|
||||
+ (instancetype)defaultProgressIndicatorView {
|
||||
CircleProgressIndicatorView *view = [[CircleProgressIndicatorView alloc]
|
||||
initWithFrame:CGRectMake(.0f, .0f, 28.0f, 28.0f)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
return view;
|
||||
}
|
||||
|
||||
+ (instancetype)progressIndicatorViewWithSize:(CGSize)size {
|
||||
CircleProgressIndicatorView *view = [[CircleProgressIndicatorView alloc]
|
||||
initWithFrame:CGRectMake(.0f, .0f, size.width, size.height)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
return view;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)commonInit {
|
||||
_progressLineColor = [self defaultLineColor];
|
||||
_progressLineWidth = [self defaultLineWidth];
|
||||
|
||||
_progressView = [[CircleProgressView alloc] initWithFrame:self.bounds];
|
||||
[_progressView setLineColor:[self defaultLineColor]];
|
||||
[_progressView setLineWidth:[self defaultLineWidth]];
|
||||
[self addSubview:_progressView];
|
||||
|
||||
_circleIconView = [[CircleIconView alloc] initWithFrame:self.bounds];
|
||||
[_circleIconView setLineColor:[self defaultLineColor]];
|
||||
[_circleIconView setLineWidth:[self defaultLineWidth]];
|
||||
[self addSubview:_circleIconView];
|
||||
}
|
||||
|
||||
#pragma mark - stop gesture recognizer
|
||||
|
||||
- (void)addStopGestureRecognizer {
|
||||
if (self.stopLoadingTap) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.stopLoadingTap = [[UITapGestureRecognizer alloc]
|
||||
initWithTarget:self
|
||||
action:@selector(stopLoadingTapped)];
|
||||
[self addGestureRecognizer:self.stopLoadingTap];
|
||||
}
|
||||
|
||||
- (void)removeStopGestureRecognizer {
|
||||
if (self.stopLoadingTap) {
|
||||
[self removeGestureRecognizer:self.stopLoadingTap];
|
||||
self.stopLoadingTap = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)stopLoadingTapped {
|
||||
[self removeStopGestureRecognizer];
|
||||
}
|
||||
|
||||
#pragma mark - Animations
|
||||
|
||||
- (void)prepareForLoading {
|
||||
[self removeStopGestureRecognizer];
|
||||
[self.progressView prepareForLoading];
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setProgressType:(CircleProgressType)progressType {
|
||||
_progressType = progressType;
|
||||
[self updateIconViewType];
|
||||
}
|
||||
|
||||
- (void)setProgressStatus:(CircleProgressStatus)progressStatus {
|
||||
_progressStatus = progressStatus;
|
||||
|
||||
[self.progressView finishPrepareForLoading];
|
||||
[self.progressView setLineColor:self.progressLineColor];
|
||||
[self setProgressType:_progressType];
|
||||
|
||||
switch (_progressStatus) {
|
||||
case CircleProgressStatusFailed:
|
||||
[self.progressView setLineColor:[UIColor clearColor]];
|
||||
break;
|
||||
case CircleProgressStatusStarting:
|
||||
[self prepareForLoading];
|
||||
break;
|
||||
case CircleProgressStatusInProgress:
|
||||
if (self.supportsCancel) {
|
||||
[self addStopGestureRecognizer];
|
||||
}
|
||||
break;
|
||||
case CircleProgressStatusCompleted:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateIconViewType {
|
||||
switch (_progressType) {
|
||||
case CircleProgressTypeUndefined:
|
||||
case CircleProgressTypeIcon:
|
||||
case CircleProgressTypeTimer:
|
||||
[self.circleIconView setType:CircleIconTypeText];
|
||||
break;
|
||||
case CircleProgressTypeUpload:
|
||||
[self.circleIconView setType:CircleIconTypeArrowUp];
|
||||
break;
|
||||
case CircleProgressTypeDownload:
|
||||
[self.circleIconView setType:CircleIconTypeArrowDown];
|
||||
break;
|
||||
}
|
||||
|
||||
switch (_progressStatus) {
|
||||
case CircleProgressStatusFailed:
|
||||
[self.circleIconView setType:CircleIconTypeExclamation];
|
||||
break;
|
||||
case CircleProgressStatusInProgress:
|
||||
if (self.supportsCancel) {
|
||||
[self.circleIconView setType:CircleIconTypeStop];
|
||||
}
|
||||
break;
|
||||
case CircleProgressStatusCompleted:
|
||||
[self.circleIconView setType:CircleIconTypeCheck];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)setProgress:(CGFloat)progress {
|
||||
if (progress > 1.0) {
|
||||
progress = 1.0;
|
||||
}
|
||||
|
||||
if (_progress != progress) {
|
||||
_progress = progress;
|
||||
[self.progressView setProgress:progress];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTimerTitle:(NSAttributedString *)title {
|
||||
[self setProgressType:CircleProgressTypeTimer];
|
||||
[self.circleIconView setTitle:title];
|
||||
}
|
||||
|
||||
- (void)setTextTitle:(NSAttributedString *)title {
|
||||
[self setProgressType:CircleProgressTypeIcon];
|
||||
[self.circleIconView setTitle:title];
|
||||
}
|
||||
|
||||
- (void)setIconType:(CircleIconType)type {
|
||||
[self.circleIconView setType:type];
|
||||
}
|
||||
|
||||
#pragma mark - Default Settings
|
||||
|
||||
- (UIColor *)defaultLineColor {
|
||||
return [UIColor colorWithRed:0 green:0.47 blue:1 alpha:1.0];
|
||||
}
|
||||
|
||||
- (UIColor *)defaultRedLineColor {
|
||||
return [UIColor colorWithRed:0.92 green:0.18 blue:0.18 alpha:1.0];
|
||||
}
|
||||
|
||||
- (CGFloat)defaultLineWidth {
|
||||
return fmaxf(self.frame.size.width * 0.01, 1.02f);
|
||||
}
|
||||
|
||||
- (void)setProgressLineColor:(UIColor *)color {
|
||||
_progressLineColor = color;
|
||||
[self.progressView setLineColor:color];
|
||||
[self updateViews];
|
||||
}
|
||||
- (void)setProgressLineWidth:(CGFloat)width {
|
||||
_progressLineWidth = width;
|
||||
[self.progressView setLineWidth:width];
|
||||
[self updateViews];
|
||||
}
|
||||
|
||||
- (void)updateViews {
|
||||
[self setProgressStatus:self.progressStatus];
|
||||
[self setProgressType:self.progressType];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
@import UIKit;
|
||||
|
||||
@interface BMACircleProgressView : UIView
|
||||
@interface CircleProgressView : UIView
|
||||
- (void)prepareForLoading;
|
||||
- (void)finishPrepareForLoading;
|
||||
- (void)setProgress:(CGFloat)progress;
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present Badoo Trading Limited.
|
||||
|
||||
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 "CircleProgressView.h"
|
||||
|
||||
@interface CircleProgressView ()
|
||||
@property(nonatomic, assign) CGFloat lineWidth;
|
||||
@property(nonatomic, strong) UIColor *lineColor;
|
||||
@property(nonatomic, strong) CAShapeLayer *bgLayer;
|
||||
@property(nonatomic, strong) CAShapeLayer *progressLayer;
|
||||
@property(nonatomic, assign, getter=isPreparingForLoading)
|
||||
BOOL preparingForLoading;
|
||||
@property(nonatomic, assign) CGFloat progress;
|
||||
@end
|
||||
|
||||
@implementation CircleProgressView
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self commonInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)commonInit {
|
||||
[self addSubLayers];
|
||||
[self updateBgLayer];
|
||||
}
|
||||
|
||||
#pragma mark - layers
|
||||
|
||||
- (void)addSubLayers {
|
||||
[self addBgLayer];
|
||||
[self addProgressLayer];
|
||||
}
|
||||
|
||||
- (void)addBgLayer {
|
||||
self.bgLayer = [CAShapeLayer layer];
|
||||
_bgLayer.strokeColor = _lineColor.CGColor;
|
||||
_bgLayer.fillColor = self.backgroundColor.CGColor;
|
||||
_bgLayer.lineCap = kCALineCapRound;
|
||||
_bgLayer.lineWidth = _lineWidth;
|
||||
[self.layer addSublayer:_bgLayer];
|
||||
}
|
||||
|
||||
- (void)addProgressLayer {
|
||||
self.progressLayer = [CAShapeLayer layer];
|
||||
_progressLayer.strokeColor = _lineColor.CGColor;
|
||||
_progressLayer.fillColor = nil;
|
||||
_progressLayer.lineCap = kCALineCapSquare;
|
||||
_progressLayer.lineWidth = _lineWidth * 2.2;
|
||||
[self.layer addSublayer:_progressLayer];
|
||||
}
|
||||
|
||||
#pragma mark - life cycle
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
_bgLayer.frame = self.bounds;
|
||||
_progressLayer.frame = self.bounds;
|
||||
}
|
||||
|
||||
#pragma mark - actions
|
||||
|
||||
- (void)prepareForLoading {
|
||||
self.preparingForLoading = YES;
|
||||
[self updateBgLayer];
|
||||
CABasicAnimation *rotationAnimation =
|
||||
[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
|
||||
rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
|
||||
rotationAnimation.duration = 1;
|
||||
rotationAnimation.cumulative = YES;
|
||||
rotationAnimation.repeatCount = HUGE_VALF;
|
||||
[_bgLayer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
|
||||
}
|
||||
|
||||
- (void)finishPrepareForLoading {
|
||||
if (self.preparingForLoading) {
|
||||
[_bgLayer removeAllAnimations];
|
||||
self.preparingForLoading = NO;
|
||||
[self updateBgLayer];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setProgress:(CGFloat)progress {
|
||||
if (progress >= 0.0 && progress <= 1.0) {
|
||||
_progress = progress;
|
||||
_progressLayer.hidden = _progress >= 1.0;
|
||||
[self updateProgressLayer];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - line style
|
||||
|
||||
- (void)setLineColor:(UIColor *)lineColor {
|
||||
_lineColor = lineColor;
|
||||
_bgLayer.strokeColor = lineColor.CGColor;
|
||||
_progressLayer.strokeColor = lineColor.CGColor;
|
||||
[self updateBgLayer];
|
||||
}
|
||||
|
||||
- (void)setLineWidth:(CGFloat)lineWidth {
|
||||
_lineWidth = lineWidth;
|
||||
_bgLayer.lineWidth = lineWidth;
|
||||
_progressLayer.lineWidth = lineWidth * 2.0;
|
||||
[self updateBgLayer];
|
||||
}
|
||||
|
||||
#pragma mark - Update Layers
|
||||
|
||||
- (void)updateBgLayer {
|
||||
CGFloat spinningGapInCircle = self.isPreparingForLoading ? 1.8 : 2.0;
|
||||
CGFloat radius = CGRectGetWidth(self.bounds) / 2 - self.lineWidth;
|
||||
CGPoint center =
|
||||
CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
|
||||
UIBezierPath *bgCircle = [UIBezierPath
|
||||
bezierPathWithArcCenter:center
|
||||
radius:radius
|
||||
startAngle:-M_PI_2
|
||||
endAngle:(spinningGapInCircle * M_PI - M_PI_2)
|
||||
clockwise:YES];
|
||||
bgCircle.lineWidth = _lineWidth;
|
||||
bgCircle.lineCapStyle = kCGLineCapRound;
|
||||
_bgLayer.path = bgCircle.CGPath;
|
||||
}
|
||||
|
||||
- (void)updateProgressLayer {
|
||||
CGFloat radius = (self.bounds.size.width - _lineWidth * 4) / 2.0;
|
||||
CGPoint center =
|
||||
CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
|
||||
UIBezierPath *progressCircle =
|
||||
[UIBezierPath bezierPathWithArcCenter:center
|
||||
radius:radius
|
||||
startAngle:-M_PI_2
|
||||
endAngle:self.progress * 2 * M_PI - M_PI_2
|
||||
clockwise:YES];
|
||||
progressCircle.lineCapStyle = kCGLineCapButt;
|
||||
progressCircle.lineWidth = _lineWidth;
|
||||
_progressLayer.path = progressCircle.CGPath;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
PODS:
|
||||
- Chatto (1.0.0)
|
||||
- ChattoAdditions (1.0.0)
|
||||
- ChattoAdditions (1.0.0):
|
||||
- Chatto
|
||||
|
||||
DEPENDENCIES:
|
||||
- Chatto (from `..`)
|
||||
|
|
@ -13,7 +14,7 @@ EXTERNAL SOURCES:
|
|||
:path: ".."
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Chatto: 8fc659c895e22c20d3d180f71f589b196d1fa840
|
||||
ChattoAdditions: f65ba0cf7b8812320e59b5d72349182e8acabbde
|
||||
Chatto: 531b14bbb7d21dfc50a86fc4ff70a90367171403
|
||||
ChattoAdditions: 27c7b59f4c1b1d51d5f37c7199164982fcc59edf
|
||||
|
||||
COCOAPODS: 0.39.0
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
../../../../../ChattoAdditions/Source/UI Components/CircleProgressIndicatorView/BMACircleIconView.h
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../../../../ChattoAdditions/Source/UI Components/CircleProgressIndicatorView/BMACircleProgressIndicatorView.h
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../../../../ChattoAdditions/Source/UI Components/CircleProgressIndicatorView/BMACircleProgressView.h
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../ChattoAdditions/Source/UI Components/CircleProgressIndicatorView/CircleIconView.h
|
||||
1
ChattoApp/Pods/Headers/Private/ChattoAdditions/CircleProgressIndicatorView.h
generated
Symbolic link
1
ChattoApp/Pods/Headers/Private/ChattoAdditions/CircleProgressIndicatorView.h
generated
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../../../../ChattoAdditions/Source/UI Components/CircleProgressIndicatorView/CircleProgressIndicatorView.h
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../ChattoAdditions/Source/UI Components/CircleProgressIndicatorView/CircleProgressView.h
|
||||
|
|
@ -10,16 +10,14 @@
|
|||
"platforms": {
|
||||
"ios": "8.0"
|
||||
},
|
||||
"authors": {
|
||||
"Diego Sanchez": "diego.sanchezr@gmail.com"
|
||||
},
|
||||
"source": {
|
||||
"git": "https://github.com/badoo/Chatto.git",
|
||||
"tag": "1.0.0"
|
||||
},
|
||||
"source_files": "Chatto/Source/**/*.{h,m,swift}",
|
||||
"public_header_files": "Chatto/Source/**/*.h",
|
||||
"requires_arc": true,
|
||||
"resources": [
|
||||
"Chatto/Source/**/*.xib",
|
||||
"Chatto/Source/**/*.storyboard",
|
||||
"Chatto/Source/**/*.xcassets"
|
||||
]
|
||||
"requires_arc": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
"platforms": {
|
||||
"ios": "8.0"
|
||||
},
|
||||
"authors": {
|
||||
"Diego Sanchez": "diego.sanchezr@gmail.com"
|
||||
},
|
||||
"source": {
|
||||
"git": "https://github.com/badoo/Chatto.git",
|
||||
"tag": "1.0.0"
|
||||
|
|
@ -21,5 +24,10 @@
|
|||
"ChattoAdditions/Source/**/*.xib",
|
||||
"ChattoAdditions/Source/**/*.storyboard",
|
||||
"ChattoAdditions/Source/**/*.xcassets"
|
||||
]
|
||||
],
|
||||
"dependencies": {
|
||||
"Chatto": [
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
PODS:
|
||||
- Chatto (1.0.0)
|
||||
- ChattoAdditions (1.0.0)
|
||||
- ChattoAdditions (1.0.0):
|
||||
- Chatto
|
||||
|
||||
DEPENDENCIES:
|
||||
- Chatto (from `..`)
|
||||
|
|
@ -13,7 +14,7 @@ EXTERNAL SOURCES:
|
|||
:path: ".."
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Chatto: 8fc659c895e22c20d3d180f71f589b196d1fa840
|
||||
ChattoAdditions: f65ba0cf7b8812320e59b5d72349182e8acabbde
|
||||
Chatto: 531b14bbb7d21dfc50a86fc4ff70a90367171403
|
||||
ChattoAdditions: 27c7b59f4c1b1d51d5f37c7199164982fcc59edf
|
||||
|
||||
COCOAPODS: 0.39.0
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -14,7 +14,7 @@
|
|||
buildForArchiving = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = 'primary'
|
||||
BlueprintIdentifier = 'E383360177DBA02B0B76A38A'
|
||||
BlueprintIdentifier = 'D44CD0F68ACDF8E657A0880C'
|
||||
BlueprintName = 'Chatto'
|
||||
ReferencedContainer = 'container:Pods.xcodeproj'
|
||||
BuildableName = 'Chatto.framework'>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
buildForArchiving = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = 'primary'
|
||||
BlueprintIdentifier = 'D5752950934E89649E339636'
|
||||
BlueprintIdentifier = 'F9049A02EAFD5FB0D459A19F'
|
||||
BlueprintName = 'ChattoAdditions'
|
||||
ReferencedContainer = 'container:Pods.xcodeproj'
|
||||
BuildableName = 'ChattoAdditions.framework'>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "ChattoAdditions.h"
|
||||
#import "BMACircleIconView.h"
|
||||
#import "BMACircleProgressIndicatorView.h"
|
||||
#import "BMACircleProgressView.h"
|
||||
#import "CircleIconView.h"
|
||||
#import "CircleProgressIndicatorView.h"
|
||||
#import "CircleProgressView.h"
|
||||
|
||||
FOUNDATION_EXPORT double ChattoAdditionsVersionNumber;
|
||||
FOUNDATION_EXPORT const unsigned char ChattoAdditionsVersionString[];
|
||||
|
|
|
|||
Loading…
Reference in New Issue