├── .gitignore
├── .swift-version
├── LICENSE
├── README.md
├── ZZCircleProgress.podspec
├── ZZCircleProgressDemo.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ └── contents.xcworkspacedata
└── xcuserdata
│ └── xiaojiutouzi.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ ├── ZZCircleProgressDemo.xcscheme
│ └── xcschememanagement.plist
├── ZZCircleProgressDemo
├── AppDelegate.h
├── AppDelegate.m
├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── Icon-App-20x20@1x.png
│ │ ├── Icon-App-20x20@2x.png
│ │ ├── Icon-App-20x20@3x.png
│ │ ├── Icon-App-29x29@1x.png
│ │ ├── Icon-App-29x29@2x.png
│ │ ├── Icon-App-29x29@3x.png
│ │ ├── Icon-App-40x40@1x.png
│ │ ├── Icon-App-40x40@2x.png
│ │ ├── Icon-App-40x40@3x.png
│ │ ├── Icon-App-57x57@1x.png
│ │ ├── Icon-App-57x57@2x.png
│ │ ├── Icon-App-60x60@2x.png
│ │ ├── Icon-App-60x60@3x.png
│ │ ├── Icon-App-72x72@1x.png
│ │ ├── Icon-App-72x72@2x.png
│ │ ├── Icon-App-76x76@1x.png
│ │ ├── Icon-App-76x76@2x.png
│ │ ├── Icon-App-83.5x83.5@2x.png
│ │ ├── Icon-Small-50x50@1x.png
│ │ ├── Icon-Small-50x50@2x.png
│ │ └── ItunesArtwork@2x.png
│ ├── Contents.json
│ └── test_point.imageset
│ │ ├── Contents.json
│ │ └── test_point@2x.png
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── Info.plist
├── Masonry
│ ├── MASCompositeConstraint.h
│ ├── MASCompositeConstraint.m
│ ├── MASConstraint+Private.h
│ ├── MASConstraint.h
│ ├── MASConstraint.m
│ ├── MASConstraintMaker.h
│ ├── MASConstraintMaker.m
│ ├── MASLayoutConstraint.h
│ ├── MASLayoutConstraint.m
│ ├── MASUtilities.h
│ ├── MASViewAttribute.h
│ ├── MASViewAttribute.m
│ ├── MASViewConstraint.h
│ ├── MASViewConstraint.m
│ ├── Masonry.h
│ ├── NSArray+MASAdditions.h
│ ├── NSArray+MASAdditions.m
│ ├── NSArray+MASShorthandAdditions.h
│ ├── NSLayoutConstraint+MASDebugAdditions.h
│ ├── NSLayoutConstraint+MASDebugAdditions.m
│ ├── View+MASAdditions.h
│ ├── View+MASAdditions.m
│ ├── View+MASShorthandAdditions.h
│ ├── ViewController+MASAdditions.h
│ └── ViewController+MASAdditions.m
├── ViewController.h
├── ViewController.m
├── ZZCircleProgress
│ ├── ZZCircleProgress.bundle
│ │ ├── circle_point1.png
│ │ ├── circle_point2.png
│ │ └── circle_point3.png
│ ├── ZZCircleProgress.h
│ ├── ZZCircleProgress.m
│ ├── ZZCountingLabel.h
│ └── ZZCountingLabel.m
└── main.m
├── ZZCircleProgress_demo.gif
└── ZZCircleProgress_logo.png
/.gitignore:
--------------------------------------------------------------------------------
1 | UserInterfaceState.xcuserstate
2 | /ZZCircleProgressDemo.xcodeproj/xcuserdata/zhouxing.xcuserdatad/xcschemes/xcschememanagement.plist
3 | /ZZCircleProgressDemo.xcodeproj/xcuserdata/zhouxing.xcuserdatad/xcschemes/ZZCircleProgressDemo.xcscheme
4 | /ZZCircleProgressDemo/.DS_Store
5 | /ZZCircleProgressDemo.xcodeproj/xcuserdata/zhouxing.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
6 | /.DS_Store
7 | .DS_Store
8 | xcshareddata
9 |
--------------------------------------------------------------------------------
/.swift-version:
--------------------------------------------------------------------------------
1 | 2.3
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ZZCircleProgress
2 |
3 |
4 |
5 |
6 |
7 | [](https://img.shields.io/badge/Language-%20Objective--C%20-orange.svg)
8 | 
9 | 
10 | 
11 | [](https://github.com/Carthage/Carthage)
12 |
13 | `ZZCircleProgress` 是一款可以高度自定义的环形进度条。你能看到的任何地方都可以进行自定义,包括圆环的开始角度、缺少角度、以及动画时长、动画刷新方式等等。而且相关的属性设置支持动态化,你可以在进度条加载完成之后随时更改他们的属性。
14 |
15 | ## 最近更新
16 | * 2019.03.01:解决`initWithFrame: pathBackColor: pathFillColor: startAngle: strokeWidth:`方法设置pathBackColor、pathFillColor方法失效问题。
17 | * 2019.01.08:解决自动布局下进度条大小展示异常的问题;去除prepareToShow属性;代码整理优化。
18 |
19 | ## 特点
20 |
21 | - [x] 可以自定义所有东西。
22 | - [x] 采用`CAAnimation`方式实现进度动画,保证了进度条的性能及流畅度。
23 | - [x] 设置开始角度及减少角度时直接传入对应的角度即可(0-360),无需进行转换。
24 | - [x] 可以在进度条初始化完成之后再次更改进度条的起始角度等属性。
25 | - [x] 可以通过storyboard、xib及纯代码方式加载。
26 | - [x] 支持cocoapods。
27 | - [x] 支持iOS7.0及之后的版本。
28 |
29 | ## 安装方式
30 |
31 | ### 通过CocoaPods。
32 | ```
33 | pod 'ZZCircleProgress'
34 | ```
35 | 或
36 | ```
37 | pod 'ZZCircleProgress', '~> 0.2.1'
38 | ```
39 | 由于上传到CocoaPods没多久。可能需要`pod setup`初始化一下。
40 |
41 |
42 | ## 使用方法
43 |
44 | ### 通过storyboard或xib方式加载。
45 | 拖入一个UIView到故事板中,并指定Class为`ZZCircleProgress`即可。
46 |
47 | ### 纯代码方式加载。
48 | ```objective-c
49 | ZZCircleProgress *progressView = [[ZZCircleProgress alloc] initWithFrame:CGRectMake(100, 100, 100, 100) pathBackColor:[UIColor lightGrayColor] pathFillColor:[UIColor redColor] startAngle:0 strokeWidth:20];
50 | [self.view addSubview:progressView];
51 | ```
52 |
53 | 初始化提供了设置坐标、线条背景色、线条填充色、开始角度及线条宽度的方法。可以设置相关属性如下。
54 |
55 | ```objective-c
56 | progressView.reduceAngle = 30;//整合进度条缺少30度
57 | progressView.pointImage.image = [UIImage imageNamed:@"test"];//设置小圆点图片
58 | progressView.duration = 2.0;//动画时长。默认为1.5
59 | progressView.showPoint = NO;//是否显示默认小圆点。默认为YES
60 | progressView.showProgressText = NO;//是否显示默认进度文本。默认为YES
61 | progressView.increaseFromLast = YES;//进度条动画是否从上次进度开始动画。默认为NO
62 | progressView.progressLabel......//progressLabel集成自UILabel。属性随意设置
63 | ```
64 |
65 | ## 效果展示
66 |
67 | 
68 |
69 |
70 | ## 更新历史:
71 | * 2019.01.08:解决自动布局下进度条大小展示异常的问题;去除prepareToShow属性;代码整理优化。
72 | * 2018.05.26:解决iOS10以下设备可能报错的问题。frameInterval和preferredFramesPerSecond进行版本判断。
73 | * 2018.05.16:发布0.1.0版本及0.2.0版本到cocoapods。(0.1.0版本包括以前draw rect实现的进度条)
74 | * 2018.03.09:ZZCACircleProgress支持属性动态修改,具体实例见demo,ZZCircleProgress增加动画时长属性。
75 | * 2017.11.24:懒加载提前调用问题修复
76 | * 2017.08.30:修复xib方式导入不显示的问题
77 |
78 |
79 | ## 问题反馈
80 |
81 | 如果使用过程发现什么问题可以随时联系我QQ:1098660224,微信:zhouxing5311或提issues。
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/ZZCircleProgress.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 |
3 | s.name = "ZZCircleProgress"
4 | s.version = "0.3.1"
5 | s.summary = "The most easy way for circle progress. You can change anything you can see!"
6 | s.homepage = "https://github.com/zhouxing5311/ZZCircleProgress"
7 | s.license = "MIT"
8 | s.author = { "zhouxing5311" => "1098660224@qq.com" }
9 | s.platform = :ios, "7.0"
10 | s.source = { :git => "https://github.com/zhouxing5311/ZZCircleProgress.git", :tag => s.version.to_s}
11 | s.source_files = "ZZCircleProgressDemo/ZZCircleProgress/**/*.{h,m}"
12 | s.resources = 'ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.bundle'
13 | s.requires_arc = true
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | D96E73C521E43ED30065F2A0 /* NSLayoutConstraint+MASDebugAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73AC21E43ED30065F2A0 /* NSLayoutConstraint+MASDebugAdditions.m */; };
11 | D96E73C621E43ED30065F2A0 /* ViewController+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73B521E43ED30065F2A0 /* ViewController+MASAdditions.m */; };
12 | D96E73C721E43ED30065F2A0 /* MASCompositeConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73B921E43ED30065F2A0 /* MASCompositeConstraint.m */; };
13 | D96E73C821E43ED30065F2A0 /* MASConstraintMaker.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73BA21E43ED30065F2A0 /* MASConstraintMaker.m */; };
14 | D96E73C921E43ED30065F2A0 /* MASLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73BB21E43ED30065F2A0 /* MASLayoutConstraint.m */; };
15 | D96E73CA21E43ED30065F2A0 /* NSArray+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73BC21E43ED30065F2A0 /* NSArray+MASAdditions.m */; };
16 | D96E73CB21E43ED30065F2A0 /* View+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73BD21E43ED30065F2A0 /* View+MASAdditions.m */; };
17 | D96E73CC21E43ED30065F2A0 /* MASConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73C021E43ED30065F2A0 /* MASConstraint.m */; };
18 | D96E73CD21E43ED30065F2A0 /* MASViewConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73C221E43ED30065F2A0 /* MASViewConstraint.m */; };
19 | D96E73CE21E43ED30065F2A0 /* MASViewAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = D96E73C321E43ED30065F2A0 /* MASViewAttribute.m */; };
20 | D973DE9D20ABD5E1004A73DE /* ZZCircleProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = D973DE9C20ABD5E1004A73DE /* ZZCircleProgress.m */; };
21 | D973DEA120ABD66D004A73DE /* ZZCountingLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D973DE9E20ABD66C004A73DE /* ZZCountingLabel.m */; };
22 | D973DEA220ABD66D004A73DE /* ZZCircleProgress.bundle in Resources */ = {isa = PBXBuildFile; fileRef = D973DE9F20ABD66C004A73DE /* ZZCircleProgress.bundle */; };
23 | E021A04D1E0CB185009C67C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E021A04C1E0CB185009C67C7 /* main.m */; };
24 | E021A0501E0CB185009C67C7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E021A04F1E0CB185009C67C7 /* AppDelegate.m */; };
25 | E021A0531E0CB185009C67C7 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E021A0521E0CB185009C67C7 /* ViewController.m */; };
26 | E021A0561E0CB185009C67C7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E021A0541E0CB185009C67C7 /* Main.storyboard */; };
27 | E021A0581E0CB185009C67C7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E021A0571E0CB185009C67C7 /* Assets.xcassets */; };
28 | E021A05B1E0CB185009C67C7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E021A0591E0CB185009C67C7 /* LaunchScreen.storyboard */; };
29 | /* End PBXBuildFile section */
30 |
31 | /* Begin PBXFileReference section */
32 | D96E73AB21E43ED30065F2A0 /* MASCompositeConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASCompositeConstraint.h; sourceTree = ""; };
33 | D96E73AC21E43ED30065F2A0 /* NSLayoutConstraint+MASDebugAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+MASDebugAdditions.m"; sourceTree = ""; };
34 | D96E73AD21E43ED30065F2A0 /* MASConstraint+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASConstraint+Private.h"; sourceTree = ""; };
35 | D96E73AE21E43ED30065F2A0 /* MASLayoutConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASLayoutConstraint.h; sourceTree = ""; };
36 | D96E73AF21E43ED30065F2A0 /* NSArray+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASShorthandAdditions.h"; sourceTree = ""; };
37 | D96E73B021E43ED30065F2A0 /* MASConstraintMaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASConstraintMaker.h; sourceTree = ""; };
38 | D96E73B121E43ED30065F2A0 /* View+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASAdditions.h"; sourceTree = ""; };
39 | D96E73B221E43ED30065F2A0 /* NSArray+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASAdditions.h"; sourceTree = ""; };
40 | D96E73B321E43ED30065F2A0 /* MASUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASUtilities.h; sourceTree = ""; };
41 | D96E73B421E43ED30065F2A0 /* MASViewAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASViewAttribute.h; sourceTree = ""; };
42 | D96E73B521E43ED30065F2A0 /* ViewController+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ViewController+MASAdditions.m"; sourceTree = ""; };
43 | D96E73B621E43ED30065F2A0 /* MASViewConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASViewConstraint.h; sourceTree = ""; };
44 | D96E73B721E43ED30065F2A0 /* MASConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASConstraint.h; sourceTree = ""; };
45 | D96E73B821E43ED30065F2A0 /* NSLayoutConstraint+MASDebugAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+MASDebugAdditions.h"; sourceTree = ""; };
46 | D96E73B921E43ED30065F2A0 /* MASCompositeConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASCompositeConstraint.m; sourceTree = ""; };
47 | D96E73BA21E43ED30065F2A0 /* MASConstraintMaker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraintMaker.m; sourceTree = ""; };
48 | D96E73BB21E43ED30065F2A0 /* MASLayoutConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASLayoutConstraint.m; sourceTree = ""; };
49 | D96E73BC21E43ED30065F2A0 /* NSArray+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+MASAdditions.m"; sourceTree = ""; };
50 | D96E73BD21E43ED30065F2A0 /* View+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "View+MASAdditions.m"; sourceTree = ""; };
51 | D96E73BE21E43ED30065F2A0 /* View+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASShorthandAdditions.h"; sourceTree = ""; };
52 | D96E73BF21E43ED30065F2A0 /* Masonry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = ""; };
53 | D96E73C021E43ED30065F2A0 /* MASConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraint.m; sourceTree = ""; };
54 | D96E73C121E43ED30065F2A0 /* ViewController+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ViewController+MASAdditions.h"; sourceTree = ""; };
55 | D96E73C221E43ED30065F2A0 /* MASViewConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASViewConstraint.m; sourceTree = ""; };
56 | D96E73C321E43ED30065F2A0 /* MASViewAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASViewAttribute.m; sourceTree = ""; };
57 | D973DE9B20ABD5E1004A73DE /* ZZCircleProgress.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ZZCircleProgress.h; sourceTree = ""; };
58 | D973DE9C20ABD5E1004A73DE /* ZZCircleProgress.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ZZCircleProgress.m; sourceTree = ""; };
59 | D973DE9E20ABD66C004A73DE /* ZZCountingLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZZCountingLabel.m; sourceTree = ""; };
60 | D973DE9F20ABD66C004A73DE /* ZZCircleProgress.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = ZZCircleProgress.bundle; sourceTree = ""; };
61 | D973DEA020ABD66C004A73DE /* ZZCountingLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZZCountingLabel.h; sourceTree = ""; };
62 | E021A0481E0CB185009C67C7 /* ZZCircleProgressDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZZCircleProgressDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
63 | E021A04C1E0CB185009C67C7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
64 | E021A04E1E0CB185009C67C7 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
65 | E021A04F1E0CB185009C67C7 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
66 | E021A0511E0CB185009C67C7 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
67 | E021A0521E0CB185009C67C7 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
68 | E021A0551E0CB185009C67C7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
69 | E021A0571E0CB185009C67C7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
70 | E021A05A1E0CB185009C67C7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
71 | E021A05C1E0CB185009C67C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
72 | /* End PBXFileReference section */
73 |
74 | /* Begin PBXFrameworksBuildPhase section */
75 | E021A0451E0CB185009C67C7 /* Frameworks */ = {
76 | isa = PBXFrameworksBuildPhase;
77 | buildActionMask = 2147483647;
78 | files = (
79 | );
80 | runOnlyForDeploymentPostprocessing = 0;
81 | };
82 | /* End PBXFrameworksBuildPhase section */
83 |
84 | /* Begin PBXGroup section */
85 | D96E73AA21E43ED30065F2A0 /* Masonry */ = {
86 | isa = PBXGroup;
87 | children = (
88 | D96E73AB21E43ED30065F2A0 /* MASCompositeConstraint.h */,
89 | D96E73B921E43ED30065F2A0 /* MASCompositeConstraint.m */,
90 | D96E73B721E43ED30065F2A0 /* MASConstraint.h */,
91 | D96E73C021E43ED30065F2A0 /* MASConstraint.m */,
92 | D96E73AD21E43ED30065F2A0 /* MASConstraint+Private.h */,
93 | D96E73B021E43ED30065F2A0 /* MASConstraintMaker.h */,
94 | D96E73BA21E43ED30065F2A0 /* MASConstraintMaker.m */,
95 | D96E73AE21E43ED30065F2A0 /* MASLayoutConstraint.h */,
96 | D96E73BB21E43ED30065F2A0 /* MASLayoutConstraint.m */,
97 | D96E73BF21E43ED30065F2A0 /* Masonry.h */,
98 | D96E73B321E43ED30065F2A0 /* MASUtilities.h */,
99 | D96E73B421E43ED30065F2A0 /* MASViewAttribute.h */,
100 | D96E73C321E43ED30065F2A0 /* MASViewAttribute.m */,
101 | D96E73B621E43ED30065F2A0 /* MASViewConstraint.h */,
102 | D96E73C221E43ED30065F2A0 /* MASViewConstraint.m */,
103 | D96E73B221E43ED30065F2A0 /* NSArray+MASAdditions.h */,
104 | D96E73BC21E43ED30065F2A0 /* NSArray+MASAdditions.m */,
105 | D96E73AF21E43ED30065F2A0 /* NSArray+MASShorthandAdditions.h */,
106 | D96E73B821E43ED30065F2A0 /* NSLayoutConstraint+MASDebugAdditions.h */,
107 | D96E73AC21E43ED30065F2A0 /* NSLayoutConstraint+MASDebugAdditions.m */,
108 | D96E73B121E43ED30065F2A0 /* View+MASAdditions.h */,
109 | D96E73BD21E43ED30065F2A0 /* View+MASAdditions.m */,
110 | D96E73BE21E43ED30065F2A0 /* View+MASShorthandAdditions.h */,
111 | D96E73C121E43ED30065F2A0 /* ViewController+MASAdditions.h */,
112 | D96E73B521E43ED30065F2A0 /* ViewController+MASAdditions.m */,
113 | );
114 | path = Masonry;
115 | sourceTree = "";
116 | };
117 | E021A03F1E0CB185009C67C7 = {
118 | isa = PBXGroup;
119 | children = (
120 | E021A04A1E0CB185009C67C7 /* ZZCircleProgressDemo */,
121 | E021A0491E0CB185009C67C7 /* Products */,
122 | );
123 | sourceTree = "";
124 | };
125 | E021A0491E0CB185009C67C7 /* Products */ = {
126 | isa = PBXGroup;
127 | children = (
128 | E021A0481E0CB185009C67C7 /* ZZCircleProgressDemo.app */,
129 | );
130 | name = Products;
131 | sourceTree = "";
132 | };
133 | E021A04A1E0CB185009C67C7 /* ZZCircleProgressDemo */ = {
134 | isa = PBXGroup;
135 | children = (
136 | D96E73AA21E43ED30065F2A0 /* Masonry */,
137 | E021A0621E0CB1F3009C67C7 /* ZZCircleProgress */,
138 | E021A0511E0CB185009C67C7 /* ViewController.h */,
139 | E021A0521E0CB185009C67C7 /* ViewController.m */,
140 | E021A04E1E0CB185009C67C7 /* AppDelegate.h */,
141 | E021A04F1E0CB185009C67C7 /* AppDelegate.m */,
142 | E021A0541E0CB185009C67C7 /* Main.storyboard */,
143 | E021A0571E0CB185009C67C7 /* Assets.xcassets */,
144 | E021A0591E0CB185009C67C7 /* LaunchScreen.storyboard */,
145 | E021A05C1E0CB185009C67C7 /* Info.plist */,
146 | E021A04B1E0CB185009C67C7 /* Supporting Files */,
147 | );
148 | path = ZZCircleProgressDemo;
149 | sourceTree = "";
150 | };
151 | E021A04B1E0CB185009C67C7 /* Supporting Files */ = {
152 | isa = PBXGroup;
153 | children = (
154 | E021A04C1E0CB185009C67C7 /* main.m */,
155 | );
156 | name = "Supporting Files";
157 | sourceTree = "";
158 | };
159 | E021A0621E0CB1F3009C67C7 /* ZZCircleProgress */ = {
160 | isa = PBXGroup;
161 | children = (
162 | D973DE9B20ABD5E1004A73DE /* ZZCircleProgress.h */,
163 | D973DE9C20ABD5E1004A73DE /* ZZCircleProgress.m */,
164 | D973DEA020ABD66C004A73DE /* ZZCountingLabel.h */,
165 | D973DE9E20ABD66C004A73DE /* ZZCountingLabel.m */,
166 | D973DE9F20ABD66C004A73DE /* ZZCircleProgress.bundle */,
167 | );
168 | path = ZZCircleProgress;
169 | sourceTree = "";
170 | };
171 | /* End PBXGroup section */
172 |
173 | /* Begin PBXNativeTarget section */
174 | E021A0471E0CB185009C67C7 /* ZZCircleProgressDemo */ = {
175 | isa = PBXNativeTarget;
176 | buildConfigurationList = E021A05F1E0CB185009C67C7 /* Build configuration list for PBXNativeTarget "ZZCircleProgressDemo" */;
177 | buildPhases = (
178 | E021A0441E0CB185009C67C7 /* Sources */,
179 | E021A0451E0CB185009C67C7 /* Frameworks */,
180 | E021A0461E0CB185009C67C7 /* Resources */,
181 | );
182 | buildRules = (
183 | );
184 | dependencies = (
185 | );
186 | name = ZZCircleProgressDemo;
187 | productName = ZZCircleProgressDemo;
188 | productReference = E021A0481E0CB185009C67C7 /* ZZCircleProgressDemo.app */;
189 | productType = "com.apple.product-type.application";
190 | };
191 | /* End PBXNativeTarget section */
192 |
193 | /* Begin PBXProject section */
194 | E021A0401E0CB185009C67C7 /* Project object */ = {
195 | isa = PBXProject;
196 | attributes = {
197 | LastUpgradeCheck = 0820;
198 | ORGANIZATIONNAME = zhouxing;
199 | TargetAttributes = {
200 | E021A0471E0CB185009C67C7 = {
201 | CreatedOnToolsVersion = 8.0;
202 | DevelopmentTeam = Z5Z8637SP3;
203 | ProvisioningStyle = Automatic;
204 | };
205 | };
206 | };
207 | buildConfigurationList = E021A0431E0CB185009C67C7 /* Build configuration list for PBXProject "ZZCircleProgressDemo" */;
208 | compatibilityVersion = "Xcode 3.2";
209 | developmentRegion = English;
210 | hasScannedForEncodings = 0;
211 | knownRegions = (
212 | en,
213 | Base,
214 | );
215 | mainGroup = E021A03F1E0CB185009C67C7;
216 | productRefGroup = E021A0491E0CB185009C67C7 /* Products */;
217 | projectDirPath = "";
218 | projectRoot = "";
219 | targets = (
220 | E021A0471E0CB185009C67C7 /* ZZCircleProgressDemo */,
221 | );
222 | };
223 | /* End PBXProject section */
224 |
225 | /* Begin PBXResourcesBuildPhase section */
226 | E021A0461E0CB185009C67C7 /* Resources */ = {
227 | isa = PBXResourcesBuildPhase;
228 | buildActionMask = 2147483647;
229 | files = (
230 | E021A05B1E0CB185009C67C7 /* LaunchScreen.storyboard in Resources */,
231 | E021A0581E0CB185009C67C7 /* Assets.xcassets in Resources */,
232 | D973DEA220ABD66D004A73DE /* ZZCircleProgress.bundle in Resources */,
233 | E021A0561E0CB185009C67C7 /* Main.storyboard in Resources */,
234 | );
235 | runOnlyForDeploymentPostprocessing = 0;
236 | };
237 | /* End PBXResourcesBuildPhase section */
238 |
239 | /* Begin PBXSourcesBuildPhase section */
240 | E021A0441E0CB185009C67C7 /* Sources */ = {
241 | isa = PBXSourcesBuildPhase;
242 | buildActionMask = 2147483647;
243 | files = (
244 | D973DE9D20ABD5E1004A73DE /* ZZCircleProgress.m in Sources */,
245 | E021A0531E0CB185009C67C7 /* ViewController.m in Sources */,
246 | D96E73C921E43ED30065F2A0 /* MASLayoutConstraint.m in Sources */,
247 | E021A0501E0CB185009C67C7 /* AppDelegate.m in Sources */,
248 | E021A04D1E0CB185009C67C7 /* main.m in Sources */,
249 | D96E73CE21E43ED30065F2A0 /* MASViewAttribute.m in Sources */,
250 | D96E73CA21E43ED30065F2A0 /* NSArray+MASAdditions.m in Sources */,
251 | D96E73C721E43ED30065F2A0 /* MASCompositeConstraint.m in Sources */,
252 | D96E73C821E43ED30065F2A0 /* MASConstraintMaker.m in Sources */,
253 | D96E73CB21E43ED30065F2A0 /* View+MASAdditions.m in Sources */,
254 | D96E73C621E43ED30065F2A0 /* ViewController+MASAdditions.m in Sources */,
255 | D973DEA120ABD66D004A73DE /* ZZCountingLabel.m in Sources */,
256 | D96E73CD21E43ED30065F2A0 /* MASViewConstraint.m in Sources */,
257 | D96E73C521E43ED30065F2A0 /* NSLayoutConstraint+MASDebugAdditions.m in Sources */,
258 | D96E73CC21E43ED30065F2A0 /* MASConstraint.m in Sources */,
259 | );
260 | runOnlyForDeploymentPostprocessing = 0;
261 | };
262 | /* End PBXSourcesBuildPhase section */
263 |
264 | /* Begin PBXVariantGroup section */
265 | E021A0541E0CB185009C67C7 /* Main.storyboard */ = {
266 | isa = PBXVariantGroup;
267 | children = (
268 | E021A0551E0CB185009C67C7 /* Base */,
269 | );
270 | name = Main.storyboard;
271 | sourceTree = "";
272 | };
273 | E021A0591E0CB185009C67C7 /* LaunchScreen.storyboard */ = {
274 | isa = PBXVariantGroup;
275 | children = (
276 | E021A05A1E0CB185009C67C7 /* Base */,
277 | );
278 | name = LaunchScreen.storyboard;
279 | sourceTree = "";
280 | };
281 | /* End PBXVariantGroup section */
282 |
283 | /* Begin XCBuildConfiguration section */
284 | E021A05D1E0CB185009C67C7 /* Debug */ = {
285 | isa = XCBuildConfiguration;
286 | buildSettings = {
287 | ALWAYS_SEARCH_USER_PATHS = NO;
288 | CLANG_ANALYZER_NONNULL = YES;
289 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
290 | CLANG_CXX_LIBRARY = "libc++";
291 | CLANG_ENABLE_MODULES = YES;
292 | CLANG_ENABLE_OBJC_ARC = YES;
293 | CLANG_WARN_BOOL_CONVERSION = YES;
294 | CLANG_WARN_CONSTANT_CONVERSION = YES;
295 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
296 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
297 | CLANG_WARN_EMPTY_BODY = YES;
298 | CLANG_WARN_ENUM_CONVERSION = YES;
299 | CLANG_WARN_INFINITE_RECURSION = YES;
300 | CLANG_WARN_INT_CONVERSION = YES;
301 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
302 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
303 | CLANG_WARN_SUSPICIOUS_MOVES = YES;
304 | CLANG_WARN_UNREACHABLE_CODE = YES;
305 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
306 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
307 | COPY_PHASE_STRIP = NO;
308 | DEBUG_INFORMATION_FORMAT = dwarf;
309 | ENABLE_STRICT_OBJC_MSGSEND = YES;
310 | ENABLE_TESTABILITY = YES;
311 | GCC_C_LANGUAGE_STANDARD = gnu99;
312 | GCC_DYNAMIC_NO_PIC = NO;
313 | GCC_NO_COMMON_BLOCKS = YES;
314 | GCC_OPTIMIZATION_LEVEL = 0;
315 | GCC_PREPROCESSOR_DEFINITIONS = (
316 | "DEBUG=1",
317 | "$(inherited)",
318 | );
319 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
320 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
321 | GCC_WARN_UNDECLARED_SELECTOR = YES;
322 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
323 | GCC_WARN_UNUSED_FUNCTION = YES;
324 | GCC_WARN_UNUSED_VARIABLE = YES;
325 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
326 | MTL_ENABLE_DEBUG_INFO = YES;
327 | ONLY_ACTIVE_ARCH = YES;
328 | SDKROOT = iphoneos;
329 | TARGETED_DEVICE_FAMILY = "1,2";
330 | };
331 | name = Debug;
332 | };
333 | E021A05E1E0CB185009C67C7 /* Release */ = {
334 | isa = XCBuildConfiguration;
335 | buildSettings = {
336 | ALWAYS_SEARCH_USER_PATHS = NO;
337 | CLANG_ANALYZER_NONNULL = YES;
338 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
339 | CLANG_CXX_LIBRARY = "libc++";
340 | CLANG_ENABLE_MODULES = YES;
341 | CLANG_ENABLE_OBJC_ARC = YES;
342 | CLANG_WARN_BOOL_CONVERSION = YES;
343 | CLANG_WARN_CONSTANT_CONVERSION = YES;
344 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
345 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
346 | CLANG_WARN_EMPTY_BODY = YES;
347 | CLANG_WARN_ENUM_CONVERSION = YES;
348 | CLANG_WARN_INFINITE_RECURSION = YES;
349 | CLANG_WARN_INT_CONVERSION = YES;
350 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
351 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
352 | CLANG_WARN_SUSPICIOUS_MOVES = YES;
353 | CLANG_WARN_UNREACHABLE_CODE = YES;
354 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
355 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
356 | COPY_PHASE_STRIP = NO;
357 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
358 | ENABLE_NS_ASSERTIONS = NO;
359 | ENABLE_STRICT_OBJC_MSGSEND = YES;
360 | GCC_C_LANGUAGE_STANDARD = gnu99;
361 | GCC_NO_COMMON_BLOCKS = YES;
362 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
363 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
364 | GCC_WARN_UNDECLARED_SELECTOR = YES;
365 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
366 | GCC_WARN_UNUSED_FUNCTION = YES;
367 | GCC_WARN_UNUSED_VARIABLE = YES;
368 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
369 | MTL_ENABLE_DEBUG_INFO = NO;
370 | SDKROOT = iphoneos;
371 | TARGETED_DEVICE_FAMILY = "1,2";
372 | VALIDATE_PRODUCT = YES;
373 | };
374 | name = Release;
375 | };
376 | E021A0601E0CB185009C67C7 /* Debug */ = {
377 | isa = XCBuildConfiguration;
378 | buildSettings = {
379 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
380 | DEVELOPMENT_TEAM = Z5Z8637SP3;
381 | INFOPLIST_FILE = ZZCircleProgressDemo/Info.plist;
382 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
384 | PRODUCT_BUNDLE_IDENTIFIER = com.zhouxing.ZZCircleProgressDemo.xx;
385 | PRODUCT_NAME = "$(TARGET_NAME)";
386 | };
387 | name = Debug;
388 | };
389 | E021A0611E0CB185009C67C7 /* Release */ = {
390 | isa = XCBuildConfiguration;
391 | buildSettings = {
392 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
393 | DEVELOPMENT_TEAM = Z5Z8637SP3;
394 | INFOPLIST_FILE = ZZCircleProgressDemo/Info.plist;
395 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
397 | PRODUCT_BUNDLE_IDENTIFIER = com.zhouxing.ZZCircleProgressDemo.xx;
398 | PRODUCT_NAME = "$(TARGET_NAME)";
399 | };
400 | name = Release;
401 | };
402 | /* End XCBuildConfiguration section */
403 |
404 | /* Begin XCConfigurationList section */
405 | E021A0431E0CB185009C67C7 /* Build configuration list for PBXProject "ZZCircleProgressDemo" */ = {
406 | isa = XCConfigurationList;
407 | buildConfigurations = (
408 | E021A05D1E0CB185009C67C7 /* Debug */,
409 | E021A05E1E0CB185009C67C7 /* Release */,
410 | );
411 | defaultConfigurationIsVisible = 0;
412 | defaultConfigurationName = Release;
413 | };
414 | E021A05F1E0CB185009C67C7 /* Build configuration list for PBXNativeTarget "ZZCircleProgressDemo" */ = {
415 | isa = XCConfigurationList;
416 | buildConfigurations = (
417 | E021A0601E0CB185009C67C7 /* Debug */,
418 | E021A0611E0CB185009C67C7 /* Release */,
419 | );
420 | defaultConfigurationIsVisible = 0;
421 | defaultConfigurationName = Release;
422 | };
423 | /* End XCConfigurationList section */
424 | };
425 | rootObject = E021A0401E0CB185009C67C7 /* Project object */;
426 | }
427 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo.xcodeproj/xcuserdata/xiaojiutouzi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo.xcodeproj/xcuserdata/xiaojiutouzi.xcuserdatad/xcschemes/ZZCircleProgressDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo.xcodeproj/xcuserdata/xiaojiutouzi.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ZZCircleProgressDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | E021A0471E0CB185009C67C7
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // ZZCircleProgressDemo
4 | //
5 | // Created by iMac on 2016/12/23.
6 | // Copyright © 2016年 zhouxing. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // ZZCircleProgressDemo
4 | //
5 | // Created by iMac on 2016/12/23.
6 | // Copyright © 2016年 zhouxing. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 |
24 | - (void)applicationWillResignActive:(UIApplication *)application {
25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
27 | }
28 |
29 |
30 | - (void)applicationDidEnterBackground:(UIApplication *)application {
31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
33 | }
34 |
35 |
36 | - (void)applicationWillEnterForeground:(UIApplication *)application {
37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
38 | }
39 |
40 |
41 | - (void)applicationDidBecomeActive:(UIApplication *)application {
42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
43 | }
44 |
45 |
46 | - (void)applicationWillTerminate:(UIApplication *)application {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "57x57",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-57x57@1x.png",
49 | "scale" : "1x"
50 | },
51 | {
52 | "size" : "57x57",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-57x57@2x.png",
55 | "scale" : "2x"
56 | },
57 | {
58 | "size" : "60x60",
59 | "idiom" : "iphone",
60 | "filename" : "Icon-App-60x60@2x.png",
61 | "scale" : "2x"
62 | },
63 | {
64 | "size" : "60x60",
65 | "idiom" : "iphone",
66 | "filename" : "Icon-App-60x60@3x.png",
67 | "scale" : "3x"
68 | },
69 | {
70 | "size" : "20x20",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-20x20@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "20x20",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-20x20@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "29x29",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-29x29@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "29x29",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-29x29@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "40x40",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-40x40@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "40x40",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-40x40@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "50x50",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-Small-50x50@1x.png",
109 | "scale" : "1x"
110 | },
111 | {
112 | "size" : "50x50",
113 | "idiom" : "ipad",
114 | "filename" : "Icon-Small-50x50@2x.png",
115 | "scale" : "2x"
116 | },
117 | {
118 | "size" : "72x72",
119 | "idiom" : "ipad",
120 | "filename" : "Icon-App-72x72@1x.png",
121 | "scale" : "1x"
122 | },
123 | {
124 | "size" : "72x72",
125 | "idiom" : "ipad",
126 | "filename" : "Icon-App-72x72@2x.png",
127 | "scale" : "2x"
128 | },
129 | {
130 | "size" : "76x76",
131 | "idiom" : "ipad",
132 | "filename" : "Icon-App-76x76@1x.png",
133 | "scale" : "1x"
134 | },
135 | {
136 | "size" : "76x76",
137 | "idiom" : "ipad",
138 | "filename" : "Icon-App-76x76@2x.png",
139 | "scale" : "2x"
140 | },
141 | {
142 | "size" : "83.5x83.5",
143 | "idiom" : "ipad",
144 | "filename" : "Icon-App-83.5x83.5@2x.png",
145 | "scale" : "2x"
146 | },
147 | {
148 | "size" : "1024x1024",
149 | "idiom" : "ios-marketing",
150 | "filename" : "ItunesArtwork@2x.png",
151 | "scale" : "1x"
152 | }
153 | ],
154 | "info" : {
155 | "version" : 1,
156 | "author" : "xcode"
157 | }
158 | }
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@1x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/Icon-Small-50x50@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/test_point.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "filename" : "test_point@2x.png",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Assets.xcassets/test_point.imageset/test_point@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/Assets.xcassets/test_point.imageset/test_point@2x.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
70 |
77 |
84 |
91 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
112 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
134 |
142 |
150 |
158 |
170 |
177 |
184 |
191 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 0.1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASCompositeConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASCompositeConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 | #import "MASUtilities.h"
11 |
12 | /**
13 | * A group of MASConstraint objects
14 | */
15 | @interface MASCompositeConstraint : MASConstraint
16 |
17 | /**
18 | * Creates a composite with a predefined array of children
19 | *
20 | * @param children child MASConstraints
21 | *
22 | * @return a composite constraint
23 | */
24 | - (id)initWithChildren:(NSArray *)children;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASCompositeConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASCompositeConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASCompositeConstraint.h"
10 | #import "MASConstraint+Private.h"
11 |
12 | @interface MASCompositeConstraint ()
13 |
14 | @property (nonatomic, strong) id mas_key;
15 | @property (nonatomic, strong) NSMutableArray *childConstraints;
16 |
17 | @end
18 |
19 | @implementation MASCompositeConstraint
20 |
21 | - (id)initWithChildren:(NSArray *)children {
22 | self = [super init];
23 | if (!self) return nil;
24 |
25 | _childConstraints = [children mutableCopy];
26 | for (MASConstraint *constraint in _childConstraints) {
27 | constraint.delegate = self;
28 | }
29 |
30 | return self;
31 | }
32 |
33 | #pragma mark - MASConstraintDelegate
34 |
35 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint {
36 | NSUInteger index = [self.childConstraints indexOfObject:constraint];
37 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint);
38 | [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint];
39 | }
40 |
41 | - (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
42 | id strongDelegate = self.delegate;
43 | MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
44 | newConstraint.delegate = self;
45 | [self.childConstraints addObject:newConstraint];
46 | return newConstraint;
47 | }
48 |
49 | #pragma mark - NSLayoutConstraint multiplier proxies
50 |
51 | - (MASConstraint * (^)(CGFloat))multipliedBy {
52 | return ^id(CGFloat multiplier) {
53 | for (MASConstraint *constraint in self.childConstraints) {
54 | constraint.multipliedBy(multiplier);
55 | }
56 | return self;
57 | };
58 | }
59 |
60 | - (MASConstraint * (^)(CGFloat))dividedBy {
61 | return ^id(CGFloat divider) {
62 | for (MASConstraint *constraint in self.childConstraints) {
63 | constraint.dividedBy(divider);
64 | }
65 | return self;
66 | };
67 | }
68 |
69 | #pragma mark - MASLayoutPriority proxy
70 |
71 | - (MASConstraint * (^)(MASLayoutPriority))priority {
72 | return ^id(MASLayoutPriority priority) {
73 | for (MASConstraint *constraint in self.childConstraints) {
74 | constraint.priority(priority);
75 | }
76 | return self;
77 | };
78 | }
79 |
80 | #pragma mark - NSLayoutRelation proxy
81 |
82 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation {
83 | return ^id(id attr, NSLayoutRelation relation) {
84 | for (MASConstraint *constraint in self.childConstraints.copy) {
85 | constraint.equalToWithRelation(attr, relation);
86 | }
87 | return self;
88 | };
89 | }
90 |
91 | #pragma mark - attribute chaining
92 |
93 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
94 | [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
95 | return self;
96 | }
97 |
98 | #pragma mark - Animator proxy
99 |
100 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
101 |
102 | - (MASConstraint *)animator {
103 | for (MASConstraint *constraint in self.childConstraints) {
104 | [constraint animator];
105 | }
106 | return self;
107 | }
108 |
109 | #endif
110 |
111 | #pragma mark - debug helpers
112 |
113 | - (MASConstraint * (^)(id))key {
114 | return ^id(id key) {
115 | self.mas_key = key;
116 | int i = 0;
117 | for (MASConstraint *constraint in self.childConstraints) {
118 | constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]);
119 | }
120 | return self;
121 | };
122 | }
123 |
124 | #pragma mark - NSLayoutConstraint constant setters
125 |
126 | - (void)setInsets:(MASEdgeInsets)insets {
127 | for (MASConstraint *constraint in self.childConstraints) {
128 | constraint.insets = insets;
129 | }
130 | }
131 |
132 | - (void)setInset:(CGFloat)inset {
133 | for (MASConstraint *constraint in self.childConstraints) {
134 | constraint.inset = inset;
135 | }
136 | }
137 |
138 | - (void)setOffset:(CGFloat)offset {
139 | for (MASConstraint *constraint in self.childConstraints) {
140 | constraint.offset = offset;
141 | }
142 | }
143 |
144 | - (void)setSizeOffset:(CGSize)sizeOffset {
145 | for (MASConstraint *constraint in self.childConstraints) {
146 | constraint.sizeOffset = sizeOffset;
147 | }
148 | }
149 |
150 | - (void)setCenterOffset:(CGPoint)centerOffset {
151 | for (MASConstraint *constraint in self.childConstraints) {
152 | constraint.centerOffset = centerOffset;
153 | }
154 | }
155 |
156 | #pragma mark - MASConstraint
157 |
158 | - (void)activate {
159 | for (MASConstraint *constraint in self.childConstraints) {
160 | [constraint activate];
161 | }
162 | }
163 |
164 | - (void)deactivate {
165 | for (MASConstraint *constraint in self.childConstraints) {
166 | [constraint deactivate];
167 | }
168 | }
169 |
170 | - (void)install {
171 | for (MASConstraint *constraint in self.childConstraints) {
172 | constraint.updateExisting = self.updateExisting;
173 | [constraint install];
174 | }
175 | }
176 |
177 | - (void)uninstall {
178 | for (MASConstraint *constraint in self.childConstraints) {
179 | [constraint uninstall];
180 | }
181 | }
182 |
183 | @end
184 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASConstraint+Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint+Private.h
3 | // Masonry
4 | //
5 | // Created by Nick Tymchenko on 29/04/14.
6 | // Copyright (c) 2014 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 |
11 | @protocol MASConstraintDelegate;
12 |
13 |
14 | @interface MASConstraint ()
15 |
16 | /**
17 | * Whether or not to check for an existing constraint instead of adding constraint
18 | */
19 | @property (nonatomic, assign) BOOL updateExisting;
20 |
21 | /**
22 | * Usually MASConstraintMaker but could be a parent MASConstraint
23 | */
24 | @property (nonatomic, weak) id delegate;
25 |
26 | /**
27 | * Based on a provided value type, is equal to calling:
28 | * NSNumber - setOffset:
29 | * NSValue with CGPoint - setPointOffset:
30 | * NSValue with CGSize - setSizeOffset:
31 | * NSValue with MASEdgeInsets - setInsets:
32 | */
33 | - (void)setLayoutConstantWithValue:(NSValue *)value;
34 |
35 | @end
36 |
37 |
38 | @interface MASConstraint (Abstract)
39 |
40 | /**
41 | * Sets the constraint relation to given NSLayoutRelation
42 | * returns a block which accepts one of the following:
43 | * MASViewAttribute, UIView, NSValue, NSArray
44 | * see readme for more details.
45 | */
46 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation;
47 |
48 | /**
49 | * Override to set a custom chaining behaviour
50 | */
51 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute;
52 |
53 | @end
54 |
55 |
56 | @protocol MASConstraintDelegate
57 |
58 | /**
59 | * Notifies the delegate when the constraint needs to be replaced with another constraint. For example
60 | * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks
61 | */
62 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint;
63 |
64 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute;
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * Enables Constraints to be created with chainable syntax
13 | * Constraint can represent single NSLayoutConstraint (MASViewConstraint)
14 | * or a group of NSLayoutConstraints (MASComposisteConstraint)
15 | */
16 | @interface MASConstraint : NSObject
17 |
18 | // Chaining Support
19 |
20 | /**
21 | * Modifies the NSLayoutConstraint constant,
22 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
23 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
24 | */
25 | - (MASConstraint * (^)(MASEdgeInsets insets))insets;
26 |
27 | /**
28 | * Modifies the NSLayoutConstraint constant,
29 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
30 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
31 | */
32 | - (MASConstraint * (^)(CGFloat inset))inset;
33 |
34 | /**
35 | * Modifies the NSLayoutConstraint constant,
36 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
37 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight
38 | */
39 | - (MASConstraint * (^)(CGSize offset))sizeOffset;
40 |
41 | /**
42 | * Modifies the NSLayoutConstraint constant,
43 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
44 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
45 | */
46 | - (MASConstraint * (^)(CGPoint offset))centerOffset;
47 |
48 | /**
49 | * Modifies the NSLayoutConstraint constant
50 | */
51 | - (MASConstraint * (^)(CGFloat offset))offset;
52 |
53 | /**
54 | * Modifies the NSLayoutConstraint constant based on a value type
55 | */
56 | - (MASConstraint * (^)(NSValue *value))valueOffset;
57 |
58 | /**
59 | * Sets the NSLayoutConstraint multiplier property
60 | */
61 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy;
62 |
63 | /**
64 | * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy
65 | */
66 | - (MASConstraint * (^)(CGFloat divider))dividedBy;
67 |
68 | /**
69 | * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority
70 | */
71 | - (MASConstraint * (^)(MASLayoutPriority priority))priority;
72 |
73 | /**
74 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow
75 | */
76 | - (MASConstraint * (^)(void))priorityLow;
77 |
78 | /**
79 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium
80 | */
81 | - (MASConstraint * (^)(void))priorityMedium;
82 |
83 | /**
84 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
85 | */
86 | - (MASConstraint * (^)(void))priorityHigh;
87 |
88 | /**
89 | * Sets the constraint relation to NSLayoutRelationEqual
90 | * returns a block which accepts one of the following:
91 | * MASViewAttribute, UIView, NSValue, NSArray
92 | * see readme for more details.
93 | */
94 | - (MASConstraint * (^)(id attr))equalTo;
95 |
96 | /**
97 | * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual
98 | * returns a block which accepts one of the following:
99 | * MASViewAttribute, UIView, NSValue, NSArray
100 | * see readme for more details.
101 | */
102 | - (MASConstraint * (^)(id attr))greaterThanOrEqualTo;
103 |
104 | /**
105 | * Sets the constraint relation to NSLayoutRelationLessThanOrEqual
106 | * returns a block which accepts one of the following:
107 | * MASViewAttribute, UIView, NSValue, NSArray
108 | * see readme for more details.
109 | */
110 | - (MASConstraint * (^)(id attr))lessThanOrEqualTo;
111 |
112 | /**
113 | * Optional semantic property which has no effect but improves the readability of constraint
114 | */
115 | - (MASConstraint *)with;
116 |
117 | /**
118 | * Optional semantic property which has no effect but improves the readability of constraint
119 | */
120 | - (MASConstraint *)and;
121 |
122 | /**
123 | * Creates a new MASCompositeConstraint with the called attribute and reciever
124 | */
125 | - (MASConstraint *)left;
126 | - (MASConstraint *)top;
127 | - (MASConstraint *)right;
128 | - (MASConstraint *)bottom;
129 | - (MASConstraint *)leading;
130 | - (MASConstraint *)trailing;
131 | - (MASConstraint *)width;
132 | - (MASConstraint *)height;
133 | - (MASConstraint *)centerX;
134 | - (MASConstraint *)centerY;
135 | - (MASConstraint *)baseline;
136 |
137 | - (MASConstraint *)firstBaseline;
138 | - (MASConstraint *)lastBaseline;
139 |
140 | #if TARGET_OS_IPHONE || TARGET_OS_TV
141 |
142 | - (MASConstraint *)leftMargin;
143 | - (MASConstraint *)rightMargin;
144 | - (MASConstraint *)topMargin;
145 | - (MASConstraint *)bottomMargin;
146 | - (MASConstraint *)leadingMargin;
147 | - (MASConstraint *)trailingMargin;
148 | - (MASConstraint *)centerXWithinMargins;
149 | - (MASConstraint *)centerYWithinMargins;
150 |
151 | #endif
152 |
153 |
154 | /**
155 | * Sets the constraint debug name
156 | */
157 | - (MASConstraint * (^)(id key))key;
158 |
159 | // NSLayoutConstraint constant Setters
160 | // for use outside of mas_updateConstraints/mas_makeConstraints blocks
161 |
162 | /**
163 | * Modifies the NSLayoutConstraint constant,
164 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
165 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
166 | */
167 | - (void)setInsets:(MASEdgeInsets)insets;
168 |
169 | /**
170 | * Modifies the NSLayoutConstraint constant,
171 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
172 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
173 | */
174 | - (void)setInset:(CGFloat)inset;
175 |
176 | /**
177 | * Modifies the NSLayoutConstraint constant,
178 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
179 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight
180 | */
181 | - (void)setSizeOffset:(CGSize)sizeOffset;
182 |
183 | /**
184 | * Modifies the NSLayoutConstraint constant,
185 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
186 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
187 | */
188 | - (void)setCenterOffset:(CGPoint)centerOffset;
189 |
190 | /**
191 | * Modifies the NSLayoutConstraint constant
192 | */
193 | - (void)setOffset:(CGFloat)offset;
194 |
195 |
196 | // NSLayoutConstraint Installation support
197 |
198 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
199 | /**
200 | * Whether or not to go through the animator proxy when modifying the constraint
201 | */
202 | @property (nonatomic, copy, readonly) MASConstraint *animator;
203 | #endif
204 |
205 | /**
206 | * Activates an NSLayoutConstraint if it's supported by an OS.
207 | * Invokes install otherwise.
208 | */
209 | - (void)activate;
210 |
211 | /**
212 | * Deactivates previously installed/activated NSLayoutConstraint.
213 | */
214 | - (void)deactivate;
215 |
216 | /**
217 | * Creates a NSLayoutConstraint and adds it to the appropriate view.
218 | */
219 | - (void)install;
220 |
221 | /**
222 | * Removes previously installed NSLayoutConstraint
223 | */
224 | - (void)uninstall;
225 |
226 | @end
227 |
228 |
229 | /**
230 | * Convenience auto-boxing macros for MASConstraint methods.
231 | *
232 | * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax.
233 | * A potential drawback of this is that the unprefixed macros will appear in global scope.
234 | */
235 | #define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__)))
236 | #define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
237 | #define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
238 |
239 | #define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__)))
240 |
241 |
242 | #ifdef MAS_SHORTHAND_GLOBALS
243 |
244 | #define equalTo(...) mas_equalTo(__VA_ARGS__)
245 | #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__)
246 | #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__)
247 |
248 | #define offset(...) mas_offset(__VA_ARGS__)
249 |
250 | #endif
251 |
252 |
253 | @interface MASConstraint (AutoboxingSupport)
254 |
255 | /**
256 | * Aliases to corresponding relation methods (for shorthand macros)
257 | * Also needed to aid autocompletion
258 | */
259 | - (MASConstraint * (^)(id attr))mas_equalTo;
260 | - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo;
261 | - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo;
262 |
263 | /**
264 | * A dummy method to aid autocompletion
265 | */
266 | - (MASConstraint * (^)(id offset))mas_offset;
267 |
268 | @end
269 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.m
3 | // Masonry
4 | //
5 | // Created by Nick Tymchenko on 1/20/14.
6 | //
7 |
8 | #import "MASConstraint.h"
9 | #import "MASConstraint+Private.h"
10 |
11 | #define MASMethodNotImplemented() \
12 | @throw [NSException exceptionWithName:NSInternalInconsistencyException \
13 | reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \
14 | userInfo:nil]
15 |
16 | @implementation MASConstraint
17 |
18 | #pragma mark - Init
19 |
20 | - (id)init {
21 | NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly.");
22 | return [super init];
23 | }
24 |
25 | #pragma mark - NSLayoutRelation proxies
26 |
27 | - (MASConstraint * (^)(id))equalTo {
28 | return ^id(id attribute) {
29 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual);
30 | };
31 | }
32 |
33 | - (MASConstraint * (^)(id))mas_equalTo {
34 | return ^id(id attribute) {
35 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual);
36 | };
37 | }
38 |
39 | - (MASConstraint * (^)(id))greaterThanOrEqualTo {
40 | return ^id(id attribute) {
41 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual);
42 | };
43 | }
44 |
45 | - (MASConstraint * (^)(id))mas_greaterThanOrEqualTo {
46 | return ^id(id attribute) {
47 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual);
48 | };
49 | }
50 |
51 | - (MASConstraint * (^)(id))lessThanOrEqualTo {
52 | return ^id(id attribute) {
53 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual);
54 | };
55 | }
56 |
57 | - (MASConstraint * (^)(id))mas_lessThanOrEqualTo {
58 | return ^id(id attribute) {
59 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual);
60 | };
61 | }
62 |
63 | #pragma mark - MASLayoutPriority proxies
64 |
65 | - (MASConstraint * (^)(void))priorityLow {
66 | return ^id{
67 | self.priority(MASLayoutPriorityDefaultLow);
68 | return self;
69 | };
70 | }
71 |
72 | - (MASConstraint * (^)(void))priorityMedium {
73 | return ^id{
74 | self.priority(MASLayoutPriorityDefaultMedium);
75 | return self;
76 | };
77 | }
78 |
79 | - (MASConstraint * (^)(void))priorityHigh {
80 | return ^id{
81 | self.priority(MASLayoutPriorityDefaultHigh);
82 | return self;
83 | };
84 | }
85 |
86 | #pragma mark - NSLayoutConstraint constant proxies
87 |
88 | - (MASConstraint * (^)(MASEdgeInsets))insets {
89 | return ^id(MASEdgeInsets insets){
90 | self.insets = insets;
91 | return self;
92 | };
93 | }
94 |
95 | - (MASConstraint * (^)(CGFloat))inset {
96 | return ^id(CGFloat inset){
97 | self.inset = inset;
98 | return self;
99 | };
100 | }
101 |
102 | - (MASConstraint * (^)(CGSize))sizeOffset {
103 | return ^id(CGSize offset) {
104 | self.sizeOffset = offset;
105 | return self;
106 | };
107 | }
108 |
109 | - (MASConstraint * (^)(CGPoint))centerOffset {
110 | return ^id(CGPoint offset) {
111 | self.centerOffset = offset;
112 | return self;
113 | };
114 | }
115 |
116 | - (MASConstraint * (^)(CGFloat))offset {
117 | return ^id(CGFloat offset){
118 | self.offset = offset;
119 | return self;
120 | };
121 | }
122 |
123 | - (MASConstraint * (^)(NSValue *value))valueOffset {
124 | return ^id(NSValue *offset) {
125 | NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset);
126 | [self setLayoutConstantWithValue:offset];
127 | return self;
128 | };
129 | }
130 |
131 | - (MASConstraint * (^)(id offset))mas_offset {
132 | // Will never be called due to macro
133 | return nil;
134 | }
135 |
136 | #pragma mark - NSLayoutConstraint constant setter
137 |
138 | - (void)setLayoutConstantWithValue:(NSValue *)value {
139 | if ([value isKindOfClass:NSNumber.class]) {
140 | self.offset = [(NSNumber *)value doubleValue];
141 | } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) {
142 | CGPoint point;
143 | [value getValue:&point];
144 | self.centerOffset = point;
145 | } else if (strcmp(value.objCType, @encode(CGSize)) == 0) {
146 | CGSize size;
147 | [value getValue:&size];
148 | self.sizeOffset = size;
149 | } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) {
150 | MASEdgeInsets insets;
151 | [value getValue:&insets];
152 | self.insets = insets;
153 | } else {
154 | NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value);
155 | }
156 | }
157 |
158 | #pragma mark - Semantic properties
159 |
160 | - (MASConstraint *)with {
161 | return self;
162 | }
163 |
164 | - (MASConstraint *)and {
165 | return self;
166 | }
167 |
168 | #pragma mark - Chaining
169 |
170 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute {
171 | MASMethodNotImplemented();
172 | }
173 |
174 | - (MASConstraint *)left {
175 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
176 | }
177 |
178 | - (MASConstraint *)top {
179 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
180 | }
181 |
182 | - (MASConstraint *)right {
183 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
184 | }
185 |
186 | - (MASConstraint *)bottom {
187 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
188 | }
189 |
190 | - (MASConstraint *)leading {
191 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
192 | }
193 |
194 | - (MASConstraint *)trailing {
195 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
196 | }
197 |
198 | - (MASConstraint *)width {
199 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
200 | }
201 |
202 | - (MASConstraint *)height {
203 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
204 | }
205 |
206 | - (MASConstraint *)centerX {
207 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
208 | }
209 |
210 | - (MASConstraint *)centerY {
211 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
212 | }
213 |
214 | - (MASConstraint *)baseline {
215 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
216 | }
217 |
218 | - (MASConstraint *)firstBaseline {
219 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline];
220 | }
221 | - (MASConstraint *)lastBaseline {
222 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline];
223 | }
224 |
225 | #if TARGET_OS_IPHONE || TARGET_OS_TV
226 |
227 | - (MASConstraint *)leftMargin {
228 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin];
229 | }
230 |
231 | - (MASConstraint *)rightMargin {
232 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin];
233 | }
234 |
235 | - (MASConstraint *)topMargin {
236 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin];
237 | }
238 |
239 | - (MASConstraint *)bottomMargin {
240 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin];
241 | }
242 |
243 | - (MASConstraint *)leadingMargin {
244 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin];
245 | }
246 |
247 | - (MASConstraint *)trailingMargin {
248 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin];
249 | }
250 |
251 | - (MASConstraint *)centerXWithinMargins {
252 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins];
253 | }
254 |
255 | - (MASConstraint *)centerYWithinMargins {
256 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins];
257 | }
258 |
259 | #endif
260 |
261 | #pragma mark - Abstract
262 |
263 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); }
264 |
265 | - (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); }
266 |
267 | - (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); }
268 |
269 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); }
270 |
271 | - (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); }
272 |
273 | - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); }
274 |
275 | - (void)setInset:(CGFloat __unused)inset { MASMethodNotImplemented(); }
276 |
277 | - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); }
278 |
279 | - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); }
280 |
281 | - (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); }
282 |
283 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
284 |
285 | - (MASConstraint *)animator { MASMethodNotImplemented(); }
286 |
287 | #endif
288 |
289 | - (void)activate { MASMethodNotImplemented(); }
290 |
291 | - (void)deactivate { MASMethodNotImplemented(); }
292 |
293 | - (void)install { MASMethodNotImplemented(); }
294 |
295 | - (void)uninstall { MASMethodNotImplemented(); }
296 |
297 | @end
298 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASConstraintMaker.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraintMaker.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 | #import "MASUtilities.h"
11 |
12 | typedef NS_OPTIONS(NSInteger, MASAttribute) {
13 | MASAttributeLeft = 1 << NSLayoutAttributeLeft,
14 | MASAttributeRight = 1 << NSLayoutAttributeRight,
15 | MASAttributeTop = 1 << NSLayoutAttributeTop,
16 | MASAttributeBottom = 1 << NSLayoutAttributeBottom,
17 | MASAttributeLeading = 1 << NSLayoutAttributeLeading,
18 | MASAttributeTrailing = 1 << NSLayoutAttributeTrailing,
19 | MASAttributeWidth = 1 << NSLayoutAttributeWidth,
20 | MASAttributeHeight = 1 << NSLayoutAttributeHeight,
21 | MASAttributeCenterX = 1 << NSLayoutAttributeCenterX,
22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY,
23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline,
24 |
25 | MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline,
26 | MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline,
27 |
28 | #if TARGET_OS_IPHONE || TARGET_OS_TV
29 |
30 | MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin,
31 | MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin,
32 | MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin,
33 | MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin,
34 | MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin,
35 | MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin,
36 | MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins,
37 | MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins,
38 |
39 | #endif
40 |
41 | };
42 |
43 | /**
44 | * Provides factory methods for creating MASConstraints.
45 | * Constraints are collected until they are ready to be installed
46 | *
47 | */
48 | @interface MASConstraintMaker : NSObject
49 |
50 | /**
51 | * The following properties return a new MASViewConstraint
52 | * with the first item set to the makers associated view and the appropriate MASViewAttribute
53 | */
54 | @property (nonatomic, strong, readonly) MASConstraint *left;
55 | @property (nonatomic, strong, readonly) MASConstraint *top;
56 | @property (nonatomic, strong, readonly) MASConstraint *right;
57 | @property (nonatomic, strong, readonly) MASConstraint *bottom;
58 | @property (nonatomic, strong, readonly) MASConstraint *leading;
59 | @property (nonatomic, strong, readonly) MASConstraint *trailing;
60 | @property (nonatomic, strong, readonly) MASConstraint *width;
61 | @property (nonatomic, strong, readonly) MASConstraint *height;
62 | @property (nonatomic, strong, readonly) MASConstraint *centerX;
63 | @property (nonatomic, strong, readonly) MASConstraint *centerY;
64 | @property (nonatomic, strong, readonly) MASConstraint *baseline;
65 |
66 | @property (nonatomic, strong, readonly) MASConstraint *firstBaseline;
67 | @property (nonatomic, strong, readonly) MASConstraint *lastBaseline;
68 |
69 | #if TARGET_OS_IPHONE || TARGET_OS_TV
70 |
71 | @property (nonatomic, strong, readonly) MASConstraint *leftMargin;
72 | @property (nonatomic, strong, readonly) MASConstraint *rightMargin;
73 | @property (nonatomic, strong, readonly) MASConstraint *topMargin;
74 | @property (nonatomic, strong, readonly) MASConstraint *bottomMargin;
75 | @property (nonatomic, strong, readonly) MASConstraint *leadingMargin;
76 | @property (nonatomic, strong, readonly) MASConstraint *trailingMargin;
77 | @property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins;
78 | @property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins;
79 |
80 | #endif
81 |
82 | /**
83 | * Returns a block which creates a new MASCompositeConstraint with the first item set
84 | * to the makers associated view and children corresponding to the set bits in the
85 | * MASAttribute parameter. Combine multiple attributes via binary-or.
86 | */
87 | @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs);
88 |
89 | /**
90 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
91 | * which generates the appropriate MASViewConstraint children (top, left, bottom, right)
92 | * with the first item set to the makers associated view
93 | */
94 | @property (nonatomic, strong, readonly) MASConstraint *edges;
95 |
96 | /**
97 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
98 | * which generates the appropriate MASViewConstraint children (width, height)
99 | * with the first item set to the makers associated view
100 | */
101 | @property (nonatomic, strong, readonly) MASConstraint *size;
102 |
103 | /**
104 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
105 | * which generates the appropriate MASViewConstraint children (centerX, centerY)
106 | * with the first item set to the makers associated view
107 | */
108 | @property (nonatomic, strong, readonly) MASConstraint *center;
109 |
110 | /**
111 | * Whether or not to check for an existing constraint instead of adding constraint
112 | */
113 | @property (nonatomic, assign) BOOL updateExisting;
114 |
115 | /**
116 | * Whether or not to remove existing constraints prior to installing
117 | */
118 | @property (nonatomic, assign) BOOL removeExisting;
119 |
120 | /**
121 | * initialises the maker with a default view
122 | *
123 | * @param view any MASConstraint are created with this view as the first item
124 | *
125 | * @return a new MASConstraintMaker
126 | */
127 | - (id)initWithView:(MAS_VIEW *)view;
128 |
129 | /**
130 | * Calls install method on any MASConstraints which have been created by this maker
131 | *
132 | * @return an array of all the installed MASConstraints
133 | */
134 | - (NSArray *)install;
135 |
136 | - (MASConstraint * (^)(dispatch_block_t))group;
137 |
138 | @end
139 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASConstraintMaker.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraintMaker.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraintMaker.h"
10 | #import "MASViewConstraint.h"
11 | #import "MASCompositeConstraint.h"
12 | #import "MASConstraint+Private.h"
13 | #import "MASViewAttribute.h"
14 | #import "View+MASAdditions.h"
15 |
16 | @interface MASConstraintMaker ()
17 |
18 | @property (nonatomic, weak) MAS_VIEW *view;
19 | @property (nonatomic, strong) NSMutableArray *constraints;
20 |
21 | @end
22 |
23 | @implementation MASConstraintMaker
24 |
25 | - (id)initWithView:(MAS_VIEW *)view {
26 | self = [super init];
27 | if (!self) return nil;
28 |
29 | self.view = view;
30 | self.constraints = NSMutableArray.new;
31 |
32 | return self;
33 | }
34 |
35 | - (NSArray *)install {
36 | if (self.removeExisting) {
37 | NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view];
38 | for (MASConstraint *constraint in installedConstraints) {
39 | [constraint uninstall];
40 | }
41 | }
42 | NSArray *constraints = self.constraints.copy;
43 | for (MASConstraint *constraint in constraints) {
44 | constraint.updateExisting = self.updateExisting;
45 | [constraint install];
46 | }
47 | [self.constraints removeAllObjects];
48 | return constraints;
49 | }
50 |
51 | #pragma mark - MASConstraintDelegate
52 |
53 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint {
54 | NSUInteger index = [self.constraints indexOfObject:constraint];
55 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint);
56 | [self.constraints replaceObjectAtIndex:index withObject:replacementConstraint];
57 | }
58 |
59 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
60 | MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute];
61 | MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute];
62 | if ([constraint isKindOfClass:MASViewConstraint.class]) {
63 | //replace with composite constraint
64 | NSArray *children = @[constraint, newConstraint];
65 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
66 | compositeConstraint.delegate = self;
67 | [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint];
68 | return compositeConstraint;
69 | }
70 | if (!constraint) {
71 | newConstraint.delegate = self;
72 | [self.constraints addObject:newConstraint];
73 | }
74 | return newConstraint;
75 | }
76 |
77 | - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs {
78 | __unused MASAttribute anyAttribute = (MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading
79 | | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX
80 | | MASAttributeCenterY | MASAttributeBaseline
81 | | MASAttributeFirstBaseline | MASAttributeLastBaseline
82 | #if TARGET_OS_IPHONE || TARGET_OS_TV
83 | | MASAttributeLeftMargin | MASAttributeRightMargin | MASAttributeTopMargin | MASAttributeBottomMargin
84 | | MASAttributeLeadingMargin | MASAttributeTrailingMargin | MASAttributeCenterXWithinMargins
85 | | MASAttributeCenterYWithinMargins
86 | #endif
87 | );
88 |
89 | NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)");
90 |
91 | NSMutableArray *attributes = [NSMutableArray array];
92 |
93 | if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left];
94 | if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right];
95 | if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top];
96 | if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom];
97 | if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading];
98 | if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing];
99 | if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width];
100 | if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height];
101 | if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX];
102 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY];
103 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline];
104 | if (attrs & MASAttributeFirstBaseline) [attributes addObject:self.view.mas_firstBaseline];
105 | if (attrs & MASAttributeLastBaseline) [attributes addObject:self.view.mas_lastBaseline];
106 |
107 | #if TARGET_OS_IPHONE || TARGET_OS_TV
108 |
109 | if (attrs & MASAttributeLeftMargin) [attributes addObject:self.view.mas_leftMargin];
110 | if (attrs & MASAttributeRightMargin) [attributes addObject:self.view.mas_rightMargin];
111 | if (attrs & MASAttributeTopMargin) [attributes addObject:self.view.mas_topMargin];
112 | if (attrs & MASAttributeBottomMargin) [attributes addObject:self.view.mas_bottomMargin];
113 | if (attrs & MASAttributeLeadingMargin) [attributes addObject:self.view.mas_leadingMargin];
114 | if (attrs & MASAttributeTrailingMargin) [attributes addObject:self.view.mas_trailingMargin];
115 | if (attrs & MASAttributeCenterXWithinMargins) [attributes addObject:self.view.mas_centerXWithinMargins];
116 | if (attrs & MASAttributeCenterYWithinMargins) [attributes addObject:self.view.mas_centerYWithinMargins];
117 |
118 | #endif
119 |
120 | NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count];
121 |
122 | for (MASViewAttribute *a in attributes) {
123 | [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]];
124 | }
125 |
126 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
127 | constraint.delegate = self;
128 | [self.constraints addObject:constraint];
129 | return constraint;
130 | }
131 |
132 | #pragma mark - standard Attributes
133 |
134 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
135 | return [self constraint:nil addConstraintWithLayoutAttribute:layoutAttribute];
136 | }
137 |
138 | - (MASConstraint *)left {
139 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
140 | }
141 |
142 | - (MASConstraint *)top {
143 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
144 | }
145 |
146 | - (MASConstraint *)right {
147 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
148 | }
149 |
150 | - (MASConstraint *)bottom {
151 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
152 | }
153 |
154 | - (MASConstraint *)leading {
155 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
156 | }
157 |
158 | - (MASConstraint *)trailing {
159 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
160 | }
161 |
162 | - (MASConstraint *)width {
163 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
164 | }
165 |
166 | - (MASConstraint *)height {
167 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
168 | }
169 |
170 | - (MASConstraint *)centerX {
171 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
172 | }
173 |
174 | - (MASConstraint *)centerY {
175 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
176 | }
177 |
178 | - (MASConstraint *)baseline {
179 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
180 | }
181 |
182 | - (MASConstraint *(^)(MASAttribute))attributes {
183 | return ^(MASAttribute attrs){
184 | return [self addConstraintWithAttributes:attrs];
185 | };
186 | }
187 |
188 | - (MASConstraint *)firstBaseline {
189 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline];
190 | }
191 |
192 | - (MASConstraint *)lastBaseline {
193 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline];
194 | }
195 |
196 | #if TARGET_OS_IPHONE || TARGET_OS_TV
197 |
198 | - (MASConstraint *)leftMargin {
199 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin];
200 | }
201 |
202 | - (MASConstraint *)rightMargin {
203 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin];
204 | }
205 |
206 | - (MASConstraint *)topMargin {
207 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin];
208 | }
209 |
210 | - (MASConstraint *)bottomMargin {
211 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin];
212 | }
213 |
214 | - (MASConstraint *)leadingMargin {
215 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin];
216 | }
217 |
218 | - (MASConstraint *)trailingMargin {
219 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin];
220 | }
221 |
222 | - (MASConstraint *)centerXWithinMargins {
223 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins];
224 | }
225 |
226 | - (MASConstraint *)centerYWithinMargins {
227 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins];
228 | }
229 |
230 | #endif
231 |
232 |
233 | #pragma mark - composite Attributes
234 |
235 | - (MASConstraint *)edges {
236 | return [self addConstraintWithAttributes:MASAttributeTop | MASAttributeLeft | MASAttributeRight | MASAttributeBottom];
237 | }
238 |
239 | - (MASConstraint *)size {
240 | return [self addConstraintWithAttributes:MASAttributeWidth | MASAttributeHeight];
241 | }
242 |
243 | - (MASConstraint *)center {
244 | return [self addConstraintWithAttributes:MASAttributeCenterX | MASAttributeCenterY];
245 | }
246 |
247 | #pragma mark - grouping
248 |
249 | - (MASConstraint *(^)(dispatch_block_t group))group {
250 | return ^id(dispatch_block_t group) {
251 | NSInteger previousCount = self.constraints.count;
252 | group();
253 |
254 | NSArray *children = [self.constraints subarrayWithRange:NSMakeRange(previousCount, self.constraints.count - previousCount)];
255 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
256 | constraint.delegate = self;
257 | return constraint;
258 | };
259 | }
260 |
261 | @end
262 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASLayoutConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASLayoutConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * When you are debugging or printing the constraints attached to a view this subclass
13 | * makes it easier to identify which constraints have been created via Masonry
14 | */
15 | @interface MASLayoutConstraint : NSLayoutConstraint
16 |
17 | /**
18 | * a key to associate with this constraint
19 | */
20 | @property (nonatomic, strong) id mas_key;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASLayoutConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASLayoutConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASLayoutConstraint.h"
10 |
11 | @implementation MASLayoutConstraint
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASUtilities.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASUtilities.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 19/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 |
13 | #if TARGET_OS_IPHONE || TARGET_OS_TV
14 |
15 | #import
16 | #define MAS_VIEW UIView
17 | #define MAS_VIEW_CONTROLLER UIViewController
18 | #define MASEdgeInsets UIEdgeInsets
19 |
20 | typedef UILayoutPriority MASLayoutPriority;
21 | static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired;
22 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh;
23 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500;
24 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow;
25 | static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel;
26 |
27 | #elif TARGET_OS_MAC
28 |
29 | #import
30 | #define MAS_VIEW NSView
31 | #define MASEdgeInsets NSEdgeInsets
32 |
33 | typedef NSLayoutPriority MASLayoutPriority;
34 | static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired;
35 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh;
36 | static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow;
37 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501;
38 | static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut;
39 | static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow;
40 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow;
41 | static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression;
42 |
43 | #endif
44 |
45 | /**
46 | * Allows you to attach keys to objects matching the variable names passed.
47 | *
48 | * view1.mas_key = @"view1", view2.mas_key = @"view2";
49 | *
50 | * is equivalent to:
51 | *
52 | * MASAttachKeys(view1, view2);
53 | */
54 | #define MASAttachKeys(...) \
55 | { \
56 | NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \
57 | for (id key in keyPairs.allKeys) { \
58 | id obj = keyPairs[key]; \
59 | NSAssert([obj respondsToSelector:@selector(setMas_key:)], \
60 | @"Cannot attach mas_key to %@", obj); \
61 | [obj setMas_key:key]; \
62 | } \
63 | }
64 |
65 | /**
66 | * Used to create object hashes
67 | * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html
68 | */
69 | #define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger))
70 | #define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch)))
71 |
72 | /**
73 | * Given a scalar or struct value, wraps it in NSValue
74 | * Based on EXPObjectify: https://github.com/specta/expecta
75 | */
76 | static inline id _MASBoxValue(const char *type, ...) {
77 | va_list v;
78 | va_start(v, type);
79 | id obj = nil;
80 | if (strcmp(type, @encode(id)) == 0) {
81 | id actual = va_arg(v, id);
82 | obj = actual;
83 | } else if (strcmp(type, @encode(CGPoint)) == 0) {
84 | CGPoint actual = (CGPoint)va_arg(v, CGPoint);
85 | obj = [NSValue value:&actual withObjCType:type];
86 | } else if (strcmp(type, @encode(CGSize)) == 0) {
87 | CGSize actual = (CGSize)va_arg(v, CGSize);
88 | obj = [NSValue value:&actual withObjCType:type];
89 | } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) {
90 | MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets);
91 | obj = [NSValue value:&actual withObjCType:type];
92 | } else if (strcmp(type, @encode(double)) == 0) {
93 | double actual = (double)va_arg(v, double);
94 | obj = [NSNumber numberWithDouble:actual];
95 | } else if (strcmp(type, @encode(float)) == 0) {
96 | float actual = (float)va_arg(v, double);
97 | obj = [NSNumber numberWithFloat:actual];
98 | } else if (strcmp(type, @encode(int)) == 0) {
99 | int actual = (int)va_arg(v, int);
100 | obj = [NSNumber numberWithInt:actual];
101 | } else if (strcmp(type, @encode(long)) == 0) {
102 | long actual = (long)va_arg(v, long);
103 | obj = [NSNumber numberWithLong:actual];
104 | } else if (strcmp(type, @encode(long long)) == 0) {
105 | long long actual = (long long)va_arg(v, long long);
106 | obj = [NSNumber numberWithLongLong:actual];
107 | } else if (strcmp(type, @encode(short)) == 0) {
108 | short actual = (short)va_arg(v, int);
109 | obj = [NSNumber numberWithShort:actual];
110 | } else if (strcmp(type, @encode(char)) == 0) {
111 | char actual = (char)va_arg(v, int);
112 | obj = [NSNumber numberWithChar:actual];
113 | } else if (strcmp(type, @encode(bool)) == 0) {
114 | bool actual = (bool)va_arg(v, int);
115 | obj = [NSNumber numberWithBool:actual];
116 | } else if (strcmp(type, @encode(unsigned char)) == 0) {
117 | unsigned char actual = (unsigned char)va_arg(v, unsigned int);
118 | obj = [NSNumber numberWithUnsignedChar:actual];
119 | } else if (strcmp(type, @encode(unsigned int)) == 0) {
120 | unsigned int actual = (unsigned int)va_arg(v, unsigned int);
121 | obj = [NSNumber numberWithUnsignedInt:actual];
122 | } else if (strcmp(type, @encode(unsigned long)) == 0) {
123 | unsigned long actual = (unsigned long)va_arg(v, unsigned long);
124 | obj = [NSNumber numberWithUnsignedLong:actual];
125 | } else if (strcmp(type, @encode(unsigned long long)) == 0) {
126 | unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long);
127 | obj = [NSNumber numberWithUnsignedLongLong:actual];
128 | } else if (strcmp(type, @encode(unsigned short)) == 0) {
129 | unsigned short actual = (unsigned short)va_arg(v, unsigned int);
130 | obj = [NSNumber numberWithUnsignedShort:actual];
131 | }
132 | va_end(v);
133 | return obj;
134 | }
135 |
136 | #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value))
137 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASViewAttribute.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASViewAttribute.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * An immutable tuple which stores the view and the related NSLayoutAttribute.
13 | * Describes part of either the left or right hand side of a constraint equation
14 | */
15 | @interface MASViewAttribute : NSObject
16 |
17 | /**
18 | * The view which the reciever relates to. Can be nil if item is not a view.
19 | */
20 | @property (nonatomic, weak, readonly) MAS_VIEW *view;
21 |
22 | /**
23 | * The item which the reciever relates to.
24 | */
25 | @property (nonatomic, weak, readonly) id item;
26 |
27 | /**
28 | * The attribute which the reciever relates to
29 | */
30 | @property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute;
31 |
32 | /**
33 | * Convenience initializer.
34 | */
35 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute;
36 |
37 | /**
38 | * The designated initializer.
39 | */
40 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute;
41 |
42 | /**
43 | * Determine whether the layoutAttribute is a size attribute
44 | *
45 | * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight
46 | */
47 | - (BOOL)isSizeAttribute;
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASViewAttribute.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASViewAttribute.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewAttribute.h"
10 |
11 | @implementation MASViewAttribute
12 |
13 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute {
14 | self = [self initWithView:view item:view layoutAttribute:layoutAttribute];
15 | return self;
16 | }
17 |
18 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute {
19 | self = [super init];
20 | if (!self) return nil;
21 |
22 | _view = view;
23 | _item = item;
24 | _layoutAttribute = layoutAttribute;
25 |
26 | return self;
27 | }
28 |
29 | - (BOOL)isSizeAttribute {
30 | return self.layoutAttribute == NSLayoutAttributeWidth
31 | || self.layoutAttribute == NSLayoutAttributeHeight;
32 | }
33 |
34 | - (BOOL)isEqual:(MASViewAttribute *)viewAttribute {
35 | if ([viewAttribute isKindOfClass:self.class]) {
36 | return self.view == viewAttribute.view
37 | && self.layoutAttribute == viewAttribute.layoutAttribute;
38 | }
39 | return [super isEqual:viewAttribute];
40 | }
41 |
42 | - (NSUInteger)hash {
43 | return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute;
44 | }
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASViewConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASViewConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewAttribute.h"
10 | #import "MASConstraint.h"
11 | #import "MASLayoutConstraint.h"
12 | #import "MASUtilities.h"
13 |
14 | /**
15 | * A single constraint.
16 | * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view
17 | */
18 | @interface MASViewConstraint : MASConstraint
19 |
20 | /**
21 | * First item/view and first attribute of the NSLayoutConstraint
22 | */
23 | @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute;
24 |
25 | /**
26 | * Second item/view and second attribute of the NSLayoutConstraint
27 | */
28 | @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute;
29 |
30 | /**
31 | * initialises the MASViewConstraint with the first part of the equation
32 | *
33 | * @param firstViewAttribute view.mas_left, view.mas_width etc.
34 | *
35 | * @return a new view constraint
36 | */
37 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute;
38 |
39 | /**
40 | * Returns all MASViewConstraints installed with this view as a first item.
41 | *
42 | * @param view A view to retrieve constraints for.
43 | *
44 | * @return An array of MASViewConstraints.
45 | */
46 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view;
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/MASViewConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASViewConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewConstraint.h"
10 | #import "MASConstraint+Private.h"
11 | #import "MASCompositeConstraint.h"
12 | #import "MASLayoutConstraint.h"
13 | #import "View+MASAdditions.h"
14 | #import
15 |
16 | @interface MAS_VIEW (MASConstraints)
17 |
18 | @property (nonatomic, readonly) NSMutableSet *mas_installedConstraints;
19 |
20 | @end
21 |
22 | @implementation MAS_VIEW (MASConstraints)
23 |
24 | static char kInstalledConstraintsKey;
25 |
26 | - (NSMutableSet *)mas_installedConstraints {
27 | NSMutableSet *constraints = objc_getAssociatedObject(self, &kInstalledConstraintsKey);
28 | if (!constraints) {
29 | constraints = [NSMutableSet set];
30 | objc_setAssociatedObject(self, &kInstalledConstraintsKey, constraints, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
31 | }
32 | return constraints;
33 | }
34 |
35 | @end
36 |
37 |
38 | @interface MASViewConstraint ()
39 |
40 | @property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute;
41 | @property (nonatomic, weak) MAS_VIEW *installedView;
42 | @property (nonatomic, weak) MASLayoutConstraint *layoutConstraint;
43 | @property (nonatomic, assign) NSLayoutRelation layoutRelation;
44 | @property (nonatomic, assign) MASLayoutPriority layoutPriority;
45 | @property (nonatomic, assign) CGFloat layoutMultiplier;
46 | @property (nonatomic, assign) CGFloat layoutConstant;
47 | @property (nonatomic, assign) BOOL hasLayoutRelation;
48 | @property (nonatomic, strong) id mas_key;
49 | @property (nonatomic, assign) BOOL useAnimator;
50 |
51 | @end
52 |
53 | @implementation MASViewConstraint
54 |
55 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute {
56 | self = [super init];
57 | if (!self) return nil;
58 |
59 | _firstViewAttribute = firstViewAttribute;
60 | self.layoutPriority = MASLayoutPriorityRequired;
61 | self.layoutMultiplier = 1;
62 |
63 | return self;
64 | }
65 |
66 | #pragma mark - NSCoping
67 |
68 | - (id)copyWithZone:(NSZone __unused *)zone {
69 | MASViewConstraint *constraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:self.firstViewAttribute];
70 | constraint.layoutConstant = self.layoutConstant;
71 | constraint.layoutRelation = self.layoutRelation;
72 | constraint.layoutPriority = self.layoutPriority;
73 | constraint.layoutMultiplier = self.layoutMultiplier;
74 | constraint.delegate = self.delegate;
75 | return constraint;
76 | }
77 |
78 | #pragma mark - Public
79 |
80 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view {
81 | return [view.mas_installedConstraints allObjects];
82 | }
83 |
84 | #pragma mark - Private
85 |
86 | - (void)setLayoutConstant:(CGFloat)layoutConstant {
87 | _layoutConstant = layoutConstant;
88 |
89 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
90 | if (self.useAnimator) {
91 | [self.layoutConstraint.animator setConstant:layoutConstant];
92 | } else {
93 | self.layoutConstraint.constant = layoutConstant;
94 | }
95 | #else
96 | self.layoutConstraint.constant = layoutConstant;
97 | #endif
98 | }
99 |
100 | - (void)setLayoutRelation:(NSLayoutRelation)layoutRelation {
101 | _layoutRelation = layoutRelation;
102 | self.hasLayoutRelation = YES;
103 | }
104 |
105 | - (BOOL)supportsActiveProperty {
106 | return [self.layoutConstraint respondsToSelector:@selector(isActive)];
107 | }
108 |
109 | - (BOOL)isActive {
110 | BOOL active = YES;
111 | if ([self supportsActiveProperty]) {
112 | active = [self.layoutConstraint isActive];
113 | }
114 |
115 | return active;
116 | }
117 |
118 | - (BOOL)hasBeenInstalled {
119 | return (self.layoutConstraint != nil) && [self isActive];
120 | }
121 |
122 | - (void)setSecondViewAttribute:(id)secondViewAttribute {
123 | if ([secondViewAttribute isKindOfClass:NSValue.class]) {
124 | [self setLayoutConstantWithValue:secondViewAttribute];
125 | } else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) {
126 | _secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
127 | } else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {
128 | MASViewAttribute *attr = secondViewAttribute;
129 | if (attr.layoutAttribute == NSLayoutAttributeNotAnAttribute) {
130 | _secondViewAttribute = [[MASViewAttribute alloc] initWithView:attr.view item:attr.item layoutAttribute:self.firstViewAttribute.layoutAttribute];;
131 | } else {
132 | _secondViewAttribute = secondViewAttribute;
133 | }
134 | } else {
135 | NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute);
136 | }
137 | }
138 |
139 | #pragma mark - NSLayoutConstraint multiplier proxies
140 |
141 | - (MASConstraint * (^)(CGFloat))multipliedBy {
142 | return ^id(CGFloat multiplier) {
143 | NSAssert(!self.hasBeenInstalled,
144 | @"Cannot modify constraint multiplier after it has been installed");
145 |
146 | self.layoutMultiplier = multiplier;
147 | return self;
148 | };
149 | }
150 |
151 |
152 | - (MASConstraint * (^)(CGFloat))dividedBy {
153 | return ^id(CGFloat divider) {
154 | NSAssert(!self.hasBeenInstalled,
155 | @"Cannot modify constraint multiplier after it has been installed");
156 |
157 | self.layoutMultiplier = 1.0/divider;
158 | return self;
159 | };
160 | }
161 |
162 | #pragma mark - MASLayoutPriority proxy
163 |
164 | - (MASConstraint * (^)(MASLayoutPriority))priority {
165 | return ^id(MASLayoutPriority priority) {
166 | NSAssert(!self.hasBeenInstalled,
167 | @"Cannot modify constraint priority after it has been installed");
168 |
169 | self.layoutPriority = priority;
170 | return self;
171 | };
172 | }
173 |
174 | #pragma mark - NSLayoutRelation proxy
175 |
176 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation {
177 | return ^id(id attribute, NSLayoutRelation relation) {
178 | if ([attribute isKindOfClass:NSArray.class]) {
179 | NSAssert(!self.hasLayoutRelation, @"Redefinition of constraint relation");
180 | NSMutableArray *children = NSMutableArray.new;
181 | for (id attr in attribute) {
182 | MASViewConstraint *viewConstraint = [self copy];
183 | viewConstraint.layoutRelation = relation;
184 | viewConstraint.secondViewAttribute = attr;
185 | [children addObject:viewConstraint];
186 | }
187 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
188 | compositeConstraint.delegate = self.delegate;
189 | [self.delegate constraint:self shouldBeReplacedWithConstraint:compositeConstraint];
190 | return compositeConstraint;
191 | } else {
192 | NSAssert(!self.hasLayoutRelation || self.layoutRelation == relation && [attribute isKindOfClass:NSValue.class], @"Redefinition of constraint relation");
193 | self.layoutRelation = relation;
194 | self.secondViewAttribute = attribute;
195 | return self;
196 | }
197 | };
198 | }
199 |
200 | #pragma mark - Semantic properties
201 |
202 | - (MASConstraint *)with {
203 | return self;
204 | }
205 |
206 | - (MASConstraint *)and {
207 | return self;
208 | }
209 |
210 | #pragma mark - attribute chaining
211 |
212 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
213 | NSAssert(!self.hasLayoutRelation, @"Attributes should be chained before defining the constraint relation");
214 |
215 | return [self.delegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
216 | }
217 |
218 | #pragma mark - Animator proxy
219 |
220 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
221 |
222 | - (MASConstraint *)animator {
223 | self.useAnimator = YES;
224 | return self;
225 | }
226 |
227 | #endif
228 |
229 | #pragma mark - debug helpers
230 |
231 | - (MASConstraint * (^)(id))key {
232 | return ^id(id key) {
233 | self.mas_key = key;
234 | return self;
235 | };
236 | }
237 |
238 | #pragma mark - NSLayoutConstraint constant setters
239 |
240 | - (void)setInsets:(MASEdgeInsets)insets {
241 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
242 | switch (layoutAttribute) {
243 | case NSLayoutAttributeLeft:
244 | case NSLayoutAttributeLeading:
245 | self.layoutConstant = insets.left;
246 | break;
247 | case NSLayoutAttributeTop:
248 | self.layoutConstant = insets.top;
249 | break;
250 | case NSLayoutAttributeBottom:
251 | self.layoutConstant = -insets.bottom;
252 | break;
253 | case NSLayoutAttributeRight:
254 | case NSLayoutAttributeTrailing:
255 | self.layoutConstant = -insets.right;
256 | break;
257 | default:
258 | break;
259 | }
260 | }
261 |
262 | - (void)setInset:(CGFloat)inset {
263 | [self setInsets:(MASEdgeInsets){.top = inset, .left = inset, .bottom = inset, .right = inset}];
264 | }
265 |
266 | - (void)setOffset:(CGFloat)offset {
267 | self.layoutConstant = offset;
268 | }
269 |
270 | - (void)setSizeOffset:(CGSize)sizeOffset {
271 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
272 | switch (layoutAttribute) {
273 | case NSLayoutAttributeWidth:
274 | self.layoutConstant = sizeOffset.width;
275 | break;
276 | case NSLayoutAttributeHeight:
277 | self.layoutConstant = sizeOffset.height;
278 | break;
279 | default:
280 | break;
281 | }
282 | }
283 |
284 | - (void)setCenterOffset:(CGPoint)centerOffset {
285 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
286 | switch (layoutAttribute) {
287 | case NSLayoutAttributeCenterX:
288 | self.layoutConstant = centerOffset.x;
289 | break;
290 | case NSLayoutAttributeCenterY:
291 | self.layoutConstant = centerOffset.y;
292 | break;
293 | default:
294 | break;
295 | }
296 | }
297 |
298 | #pragma mark - MASConstraint
299 |
300 | - (void)activate {
301 | [self install];
302 | }
303 |
304 | - (void)deactivate {
305 | [self uninstall];
306 | }
307 |
308 | - (void)install {
309 | if (self.hasBeenInstalled) {
310 | return;
311 | }
312 |
313 | if ([self supportsActiveProperty] && self.layoutConstraint) {
314 | self.layoutConstraint.active = YES;
315 | [self.firstViewAttribute.view.mas_installedConstraints addObject:self];
316 | return;
317 | }
318 |
319 | MAS_VIEW *firstLayoutItem = self.firstViewAttribute.item;
320 | NSLayoutAttribute firstLayoutAttribute = self.firstViewAttribute.layoutAttribute;
321 | MAS_VIEW *secondLayoutItem = self.secondViewAttribute.item;
322 | NSLayoutAttribute secondLayoutAttribute = self.secondViewAttribute.layoutAttribute;
323 |
324 | // alignment attributes must have a secondViewAttribute
325 | // therefore we assume that is refering to superview
326 | // eg make.left.equalTo(@10)
327 | if (!self.firstViewAttribute.isSizeAttribute && !self.secondViewAttribute) {
328 | secondLayoutItem = self.firstViewAttribute.view.superview;
329 | secondLayoutAttribute = firstLayoutAttribute;
330 | }
331 |
332 | MASLayoutConstraint *layoutConstraint
333 | = [MASLayoutConstraint constraintWithItem:firstLayoutItem
334 | attribute:firstLayoutAttribute
335 | relatedBy:self.layoutRelation
336 | toItem:secondLayoutItem
337 | attribute:secondLayoutAttribute
338 | multiplier:self.layoutMultiplier
339 | constant:self.layoutConstant];
340 |
341 | layoutConstraint.priority = self.layoutPriority;
342 | layoutConstraint.mas_key = self.mas_key;
343 |
344 | if (self.secondViewAttribute.view) {
345 | MAS_VIEW *closestCommonSuperview = [self.firstViewAttribute.view mas_closestCommonSuperview:self.secondViewAttribute.view];
346 | NSAssert(closestCommonSuperview,
347 | @"couldn't find a common superview for %@ and %@",
348 | self.firstViewAttribute.view, self.secondViewAttribute.view);
349 | self.installedView = closestCommonSuperview;
350 | } else if (self.firstViewAttribute.isSizeAttribute) {
351 | self.installedView = self.firstViewAttribute.view;
352 | } else {
353 | self.installedView = self.firstViewAttribute.view.superview;
354 | }
355 |
356 |
357 | MASLayoutConstraint *existingConstraint = nil;
358 | if (self.updateExisting) {
359 | existingConstraint = [self layoutConstraintSimilarTo:layoutConstraint];
360 | }
361 | if (existingConstraint) {
362 | // just update the constant
363 | existingConstraint.constant = layoutConstraint.constant;
364 | self.layoutConstraint = existingConstraint;
365 | } else {
366 | [self.installedView addConstraint:layoutConstraint];
367 | self.layoutConstraint = layoutConstraint;
368 | [firstLayoutItem.mas_installedConstraints addObject:self];
369 | }
370 | }
371 |
372 | - (MASLayoutConstraint *)layoutConstraintSimilarTo:(MASLayoutConstraint *)layoutConstraint {
373 | // check if any constraints are the same apart from the only mutable property constant
374 |
375 | // go through constraints in reverse as we do not want to match auto-resizing or interface builder constraints
376 | // and they are likely to be added first.
377 | for (NSLayoutConstraint *existingConstraint in self.installedView.constraints.reverseObjectEnumerator) {
378 | if (![existingConstraint isKindOfClass:MASLayoutConstraint.class]) continue;
379 | if (existingConstraint.firstItem != layoutConstraint.firstItem) continue;
380 | if (existingConstraint.secondItem != layoutConstraint.secondItem) continue;
381 | if (existingConstraint.firstAttribute != layoutConstraint.firstAttribute) continue;
382 | if (existingConstraint.secondAttribute != layoutConstraint.secondAttribute) continue;
383 | if (existingConstraint.relation != layoutConstraint.relation) continue;
384 | if (existingConstraint.multiplier != layoutConstraint.multiplier) continue;
385 | if (existingConstraint.priority != layoutConstraint.priority) continue;
386 |
387 | return (id)existingConstraint;
388 | }
389 | return nil;
390 | }
391 |
392 | - (void)uninstall {
393 | if ([self supportsActiveProperty]) {
394 | self.layoutConstraint.active = NO;
395 | [self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
396 | return;
397 | }
398 |
399 | [self.installedView removeConstraint:self.layoutConstraint];
400 | self.layoutConstraint = nil;
401 | self.installedView = nil;
402 |
403 | [self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
404 | }
405 |
406 | @end
407 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/Masonry.h:
--------------------------------------------------------------------------------
1 | //
2 | // Masonry.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for Masonry.
12 | FOUNDATION_EXPORT double MasonryVersionNumber;
13 |
14 | //! Project version string for Masonry.
15 | FOUNDATION_EXPORT const unsigned char MasonryVersionString[];
16 |
17 | #import "MASUtilities.h"
18 | #import "View+MASAdditions.h"
19 | #import "View+MASShorthandAdditions.h"
20 | #import "ViewController+MASAdditions.h"
21 | #import "NSArray+MASAdditions.h"
22 | #import "NSArray+MASShorthandAdditions.h"
23 | #import "MASConstraint.h"
24 | #import "MASCompositeConstraint.h"
25 | #import "MASViewAttribute.h"
26 | #import "MASViewConstraint.h"
27 | #import "MASConstraintMaker.h"
28 | #import "MASLayoutConstraint.h"
29 | #import "NSLayoutConstraint+MASDebugAdditions.h"
30 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/NSArray+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASAdditions.h
3 | //
4 | //
5 | // Created by Daniel Hammond on 11/26/13.
6 | //
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | typedef NS_ENUM(NSUInteger, MASAxisType) {
14 | MASAxisTypeHorizontal,
15 | MASAxisTypeVertical
16 | };
17 |
18 | @interface NSArray (MASAdditions)
19 |
20 | /**
21 | * Creates a MASConstraintMaker with each view in the callee.
22 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view
23 | *
24 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
25 | *
26 | * @return Array of created MASConstraints
27 | */
28 | - (NSArray *)mas_makeConstraints:(void (NS_NOESCAPE ^)(MASConstraintMaker *make))block;
29 |
30 | /**
31 | * Creates a MASConstraintMaker with each view in the callee.
32 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view.
33 | * If an existing constraint exists then it will be updated instead.
34 | *
35 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
36 | *
37 | * @return Array of created/updated MASConstraints
38 | */
39 | - (NSArray *)mas_updateConstraints:(void (NS_NOESCAPE ^)(MASConstraintMaker *make))block;
40 |
41 | /**
42 | * Creates a MASConstraintMaker with each view in the callee.
43 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view.
44 | * All constraints previously installed for the views will be removed.
45 | *
46 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
47 | *
48 | * @return Array of created/updated MASConstraints
49 | */
50 | - (NSArray *)mas_remakeConstraints:(void (NS_NOESCAPE ^)(MASConstraintMaker *make))block;
51 |
52 | /**
53 | * distribute with fixed spacing
54 | *
55 | * @param axisType which axis to distribute items along
56 | * @param fixedSpacing the spacing between each item
57 | * @param leadSpacing the spacing before the first item and the container
58 | * @param tailSpacing the spacing after the last item and the container
59 | */
60 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;
61 |
62 | /**
63 | * distribute with fixed item size
64 | *
65 | * @param axisType which axis to distribute items along
66 | * @param fixedItemLength the fixed length of each item
67 | * @param leadSpacing the spacing before the first item and the container
68 | * @param tailSpacing the spacing after the last item and the container
69 | */
70 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;
71 |
72 | @end
73 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/NSArray+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASAdditions.m
3 | //
4 | //
5 | // Created by Daniel Hammond on 11/26/13.
6 | //
7 | //
8 |
9 | #import "NSArray+MASAdditions.h"
10 | #import "View+MASAdditions.h"
11 |
12 | @implementation NSArray (MASAdditions)
13 |
14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block {
15 | NSMutableArray *constraints = [NSMutableArray array];
16 | for (MAS_VIEW *view in self) {
17 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
18 | [constraints addObjectsFromArray:[view mas_makeConstraints:block]];
19 | }
20 | return constraints;
21 | }
22 |
23 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block {
24 | NSMutableArray *constraints = [NSMutableArray array];
25 | for (MAS_VIEW *view in self) {
26 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
27 | [constraints addObjectsFromArray:[view mas_updateConstraints:block]];
28 | }
29 | return constraints;
30 | }
31 |
32 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
33 | NSMutableArray *constraints = [NSMutableArray array];
34 | for (MAS_VIEW *view in self) {
35 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
36 | [constraints addObjectsFromArray:[view mas_remakeConstraints:block]];
37 | }
38 | return constraints;
39 | }
40 |
41 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing {
42 | if (self.count < 2) {
43 | NSAssert(self.count>1,@"views to distribute need to bigger than one");
44 | return;
45 | }
46 |
47 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews];
48 | if (axisType == MASAxisTypeHorizontal) {
49 | MAS_VIEW *prev;
50 | for (int i = 0; i < self.count; i++) {
51 | MAS_VIEW *v = self[i];
52 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
53 | if (prev) {
54 | make.width.equalTo(prev);
55 | make.left.equalTo(prev.mas_right).offset(fixedSpacing);
56 | if (i == self.count - 1) {//last one
57 | make.right.equalTo(tempSuperView).offset(-tailSpacing);
58 | }
59 | }
60 | else {//first one
61 | make.left.equalTo(tempSuperView).offset(leadSpacing);
62 | }
63 |
64 | }];
65 | prev = v;
66 | }
67 | }
68 | else {
69 | MAS_VIEW *prev;
70 | for (int i = 0; i < self.count; i++) {
71 | MAS_VIEW *v = self[i];
72 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
73 | if (prev) {
74 | make.height.equalTo(prev);
75 | make.top.equalTo(prev.mas_bottom).offset(fixedSpacing);
76 | if (i == self.count - 1) {//last one
77 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing);
78 | }
79 | }
80 | else {//first one
81 | make.top.equalTo(tempSuperView).offset(leadSpacing);
82 | }
83 |
84 | }];
85 | prev = v;
86 | }
87 | }
88 | }
89 |
90 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing {
91 | if (self.count < 2) {
92 | NSAssert(self.count>1,@"views to distribute need to bigger than one");
93 | return;
94 | }
95 |
96 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews];
97 | if (axisType == MASAxisTypeHorizontal) {
98 | MAS_VIEW *prev;
99 | for (int i = 0; i < self.count; i++) {
100 | MAS_VIEW *v = self[i];
101 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
102 | make.width.equalTo(@(fixedItemLength));
103 | if (prev) {
104 | if (i == self.count - 1) {//last one
105 | make.right.equalTo(tempSuperView).offset(-tailSpacing);
106 | }
107 | else {
108 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1));
109 | make.right.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset);
110 | }
111 | }
112 | else {//first one
113 | make.left.equalTo(tempSuperView).offset(leadSpacing);
114 | }
115 | }];
116 | prev = v;
117 | }
118 | }
119 | else {
120 | MAS_VIEW *prev;
121 | for (int i = 0; i < self.count; i++) {
122 | MAS_VIEW *v = self[i];
123 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
124 | make.height.equalTo(@(fixedItemLength));
125 | if (prev) {
126 | if (i == self.count - 1) {//last one
127 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing);
128 | }
129 | else {
130 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1));
131 | make.bottom.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset);
132 | }
133 | }
134 | else {//first one
135 | make.top.equalTo(tempSuperView).offset(leadSpacing);
136 | }
137 | }];
138 | prev = v;
139 | }
140 | }
141 | }
142 |
143 | - (MAS_VIEW *)mas_commonSuperviewOfViews
144 | {
145 | MAS_VIEW *commonSuperview = nil;
146 | MAS_VIEW *previousView = nil;
147 | for (id object in self) {
148 | if ([object isKindOfClass:[MAS_VIEW class]]) {
149 | MAS_VIEW *view = (MAS_VIEW *)object;
150 | if (previousView) {
151 | commonSuperview = [view mas_closestCommonSuperview:commonSuperview];
152 | } else {
153 | commonSuperview = view;
154 | }
155 | previousView = view;
156 | }
157 | }
158 | NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy.");
159 | return commonSuperview;
160 | }
161 |
162 | @end
163 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/NSArray+MASShorthandAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASShorthandAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "NSArray+MASAdditions.h"
10 |
11 | #ifdef MAS_SHORTHAND
12 |
13 | /**
14 | * Shorthand array additions without the 'mas_' prefixes,
15 | * only enabled if MAS_SHORTHAND is defined
16 | */
17 | @interface NSArray (MASShorthandAdditions)
18 |
19 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
20 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
21 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
22 |
23 | @end
24 |
25 | @implementation NSArray (MASShorthandAdditions)
26 |
27 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
28 | return [self mas_makeConstraints:block];
29 | }
30 |
31 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
32 | return [self mas_updateConstraints:block];
33 | }
34 |
35 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
36 | return [self mas_remakeConstraints:block];
37 | }
38 |
39 | @end
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/NSLayoutConstraint+MASDebugAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSLayoutConstraint+MASDebugAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * makes debug and log output of NSLayoutConstraints more readable
13 | */
14 | @interface NSLayoutConstraint (MASDebugAdditions)
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/NSLayoutConstraint+MASDebugAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSLayoutConstraint+MASDebugAdditions.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "NSLayoutConstraint+MASDebugAdditions.h"
10 | #import "MASConstraint.h"
11 | #import "MASLayoutConstraint.h"
12 |
13 | @implementation NSLayoutConstraint (MASDebugAdditions)
14 |
15 | #pragma mark - description maps
16 |
17 | + (NSDictionary *)layoutRelationDescriptionsByValue {
18 | static dispatch_once_t once;
19 | static NSDictionary *descriptionMap;
20 | dispatch_once(&once, ^{
21 | descriptionMap = @{
22 | @(NSLayoutRelationEqual) : @"==",
23 | @(NSLayoutRelationGreaterThanOrEqual) : @">=",
24 | @(NSLayoutRelationLessThanOrEqual) : @"<=",
25 | };
26 | });
27 | return descriptionMap;
28 | }
29 |
30 | + (NSDictionary *)layoutAttributeDescriptionsByValue {
31 | static dispatch_once_t once;
32 | static NSDictionary *descriptionMap;
33 | dispatch_once(&once, ^{
34 | descriptionMap = @{
35 | @(NSLayoutAttributeTop) : @"top",
36 | @(NSLayoutAttributeLeft) : @"left",
37 | @(NSLayoutAttributeBottom) : @"bottom",
38 | @(NSLayoutAttributeRight) : @"right",
39 | @(NSLayoutAttributeLeading) : @"leading",
40 | @(NSLayoutAttributeTrailing) : @"trailing",
41 | @(NSLayoutAttributeWidth) : @"width",
42 | @(NSLayoutAttributeHeight) : @"height",
43 | @(NSLayoutAttributeCenterX) : @"centerX",
44 | @(NSLayoutAttributeCenterY) : @"centerY",
45 | @(NSLayoutAttributeBaseline) : @"baseline",
46 | @(NSLayoutAttributeFirstBaseline) : @"firstBaseline",
47 | @(NSLayoutAttributeLastBaseline) : @"lastBaseline",
48 |
49 | #if TARGET_OS_IPHONE || TARGET_OS_TV
50 | @(NSLayoutAttributeLeftMargin) : @"leftMargin",
51 | @(NSLayoutAttributeRightMargin) : @"rightMargin",
52 | @(NSLayoutAttributeTopMargin) : @"topMargin",
53 | @(NSLayoutAttributeBottomMargin) : @"bottomMargin",
54 | @(NSLayoutAttributeLeadingMargin) : @"leadingMargin",
55 | @(NSLayoutAttributeTrailingMargin) : @"trailingMargin",
56 | @(NSLayoutAttributeCenterXWithinMargins) : @"centerXWithinMargins",
57 | @(NSLayoutAttributeCenterYWithinMargins) : @"centerYWithinMargins",
58 | #endif
59 |
60 | };
61 |
62 | });
63 | return descriptionMap;
64 | }
65 |
66 |
67 | + (NSDictionary *)layoutPriorityDescriptionsByValue {
68 | static dispatch_once_t once;
69 | static NSDictionary *descriptionMap;
70 | dispatch_once(&once, ^{
71 | #if TARGET_OS_IPHONE || TARGET_OS_TV
72 | descriptionMap = @{
73 | @(MASLayoutPriorityDefaultHigh) : @"high",
74 | @(MASLayoutPriorityDefaultLow) : @"low",
75 | @(MASLayoutPriorityDefaultMedium) : @"medium",
76 | @(MASLayoutPriorityRequired) : @"required",
77 | @(MASLayoutPriorityFittingSizeLevel) : @"fitting size",
78 | };
79 | #elif TARGET_OS_MAC
80 | descriptionMap = @{
81 | @(MASLayoutPriorityDefaultHigh) : @"high",
82 | @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window",
83 | @(MASLayoutPriorityDefaultMedium) : @"medium",
84 | @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put",
85 | @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window",
86 | @(MASLayoutPriorityDefaultLow) : @"low",
87 | @(MASLayoutPriorityFittingSizeCompression) : @"fitting size",
88 | @(MASLayoutPriorityRequired) : @"required",
89 | };
90 | #endif
91 | });
92 | return descriptionMap;
93 | }
94 |
95 | #pragma mark - description override
96 |
97 | + (NSString *)descriptionForObject:(id)obj {
98 | if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) {
99 | return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]];
100 | }
101 | return [NSString stringWithFormat:@"%@:%p", [obj class], obj];
102 | }
103 |
104 | - (NSString *)description {
105 | NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"];
106 |
107 | [description appendString:[self.class descriptionForObject:self]];
108 |
109 | [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]];
110 | if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) {
111 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.firstAttribute)]];
112 | }
113 |
114 | [description appendFormat:@" %@", self.class.layoutRelationDescriptionsByValue[@(self.relation)]];
115 |
116 | if (self.secondItem) {
117 | [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]];
118 | }
119 | if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) {
120 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.secondAttribute)]];
121 | }
122 |
123 | if (self.multiplier != 1) {
124 | [description appendFormat:@" * %g", self.multiplier];
125 | }
126 |
127 | if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) {
128 | [description appendFormat:@" %g", self.constant];
129 | } else {
130 | if (self.constant) {
131 | [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)];
132 | }
133 | }
134 |
135 | if (self.priority != MASLayoutPriorityRequired) {
136 | [description appendFormat:@" ^%@", self.class.layoutPriorityDescriptionsByValue[@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]];
137 | }
138 |
139 | [description appendString:@">"];
140 | return description;
141 | }
142 |
143 | @end
144 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/View+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | /**
14 | * Provides constraint maker block
15 | * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs
16 | */
17 | @interface MAS_VIEW (MASAdditions)
18 |
19 | /**
20 | * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute
21 | */
22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom;
26 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading;
27 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing;
28 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_width;
29 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_height;
30 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
31 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr);
34 |
35 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_firstBaseline;
36 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_lastBaseline;
37 |
38 | #if TARGET_OS_IPHONE || TARGET_OS_TV
39 |
40 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin;
41 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin;
42 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin;
43 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin;
44 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin;
45 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin;
46 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins;
47 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins;
48 |
49 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuide NS_AVAILABLE_IOS(11.0);
50 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0);
51 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0);
52 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0);
53 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0);
54 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0);
55 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
56 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0);
57 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0);
58 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
59 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);
60 |
61 | #endif
62 |
63 | /**
64 | * a key to associate with this view
65 | */
66 | @property (nonatomic, strong) id mas_key;
67 |
68 | /**
69 | * Finds the closest common superview between this view and another view
70 | *
71 | * @param view other view
72 | *
73 | * @return returns nil if common superview could not be found
74 | */
75 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view;
76 |
77 | /**
78 | * Creates a MASConstraintMaker with the callee view.
79 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing
80 | *
81 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
82 | *
83 | * @return Array of created MASConstraints
84 | */
85 | - (NSArray *)mas_makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
86 |
87 | /**
88 | * Creates a MASConstraintMaker with the callee view.
89 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
90 | * If an existing constraint exists then it will be updated instead.
91 | *
92 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
93 | *
94 | * @return Array of created/updated MASConstraints
95 | */
96 | - (NSArray *)mas_updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
97 |
98 | /**
99 | * Creates a MASConstraintMaker with the callee view.
100 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
101 | * All constraints previously installed for the view will be removed.
102 | *
103 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
104 | *
105 | * @return Array of created/updated MASConstraints
106 | */
107 | - (NSArray *)mas_remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *make))block;
108 |
109 | @end
110 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/View+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASAdditions.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "View+MASAdditions.h"
10 | #import
11 |
12 | @implementation MAS_VIEW (MASAdditions)
13 |
14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block {
15 | self.translatesAutoresizingMaskIntoConstraints = NO;
16 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
17 | block(constraintMaker);
18 | return [constraintMaker install];
19 | }
20 |
21 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block {
22 | self.translatesAutoresizingMaskIntoConstraints = NO;
23 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
24 | constraintMaker.updateExisting = YES;
25 | block(constraintMaker);
26 | return [constraintMaker install];
27 | }
28 |
29 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
30 | self.translatesAutoresizingMaskIntoConstraints = NO;
31 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
32 | constraintMaker.removeExisting = YES;
33 | block(constraintMaker);
34 | return [constraintMaker install];
35 | }
36 |
37 | #pragma mark - NSLayoutAttribute properties
38 |
39 | - (MASViewAttribute *)mas_left {
40 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft];
41 | }
42 |
43 | - (MASViewAttribute *)mas_top {
44 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop];
45 | }
46 |
47 | - (MASViewAttribute *)mas_right {
48 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight];
49 | }
50 |
51 | - (MASViewAttribute *)mas_bottom {
52 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom];
53 | }
54 |
55 | - (MASViewAttribute *)mas_leading {
56 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading];
57 | }
58 |
59 | - (MASViewAttribute *)mas_trailing {
60 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing];
61 | }
62 |
63 | - (MASViewAttribute *)mas_width {
64 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth];
65 | }
66 |
67 | - (MASViewAttribute *)mas_height {
68 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight];
69 | }
70 |
71 | - (MASViewAttribute *)mas_centerX {
72 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX];
73 | }
74 |
75 | - (MASViewAttribute *)mas_centerY {
76 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY];
77 | }
78 |
79 | - (MASViewAttribute *)mas_baseline {
80 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline];
81 | }
82 |
83 | - (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute
84 | {
85 | return ^(NSLayoutAttribute attr) {
86 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr];
87 | };
88 | }
89 |
90 | - (MASViewAttribute *)mas_firstBaseline {
91 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeFirstBaseline];
92 | }
93 | - (MASViewAttribute *)mas_lastBaseline {
94 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLastBaseline];
95 | }
96 |
97 | #if TARGET_OS_IPHONE || TARGET_OS_TV
98 |
99 | - (MASViewAttribute *)mas_leftMargin {
100 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeftMargin];
101 | }
102 |
103 | - (MASViewAttribute *)mas_rightMargin {
104 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRightMargin];
105 | }
106 |
107 | - (MASViewAttribute *)mas_topMargin {
108 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTopMargin];
109 | }
110 |
111 | - (MASViewAttribute *)mas_bottomMargin {
112 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottomMargin];
113 | }
114 |
115 | - (MASViewAttribute *)mas_leadingMargin {
116 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeadingMargin];
117 | }
118 |
119 | - (MASViewAttribute *)mas_trailingMargin {
120 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailingMargin];
121 | }
122 |
123 | - (MASViewAttribute *)mas_centerXWithinMargins {
124 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterXWithinMargins];
125 | }
126 |
127 | - (MASViewAttribute *)mas_centerYWithinMargins {
128 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterYWithinMargins];
129 | }
130 |
131 | - (MASViewAttribute *)mas_safeAreaLayoutGuide {
132 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeNotAnAttribute];
133 | }
134 |
135 | - (MASViewAttribute *)mas_safeAreaLayoutGuideLeading {
136 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeLeading];
137 | }
138 |
139 | - (MASViewAttribute *)mas_safeAreaLayoutGuideTrailing {
140 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeTrailing];
141 | }
142 |
143 | - (MASViewAttribute *)mas_safeAreaLayoutGuideLeft {
144 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeLeft];
145 | }
146 |
147 | - (MASViewAttribute *)mas_safeAreaLayoutGuideRight {
148 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeRight];
149 | }
150 |
151 | - (MASViewAttribute *)mas_safeAreaLayoutGuideTop {
152 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeTop];
153 | }
154 |
155 | - (MASViewAttribute *)mas_safeAreaLayoutGuideBottom {
156 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
157 | }
158 |
159 | - (MASViewAttribute *)mas_safeAreaLayoutGuideWidth {
160 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeWidth];
161 | }
162 |
163 | - (MASViewAttribute *)mas_safeAreaLayoutGuideHeight {
164 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeHeight];
165 | }
166 |
167 | - (MASViewAttribute *)mas_safeAreaLayoutGuideCenterX {
168 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeCenterX];
169 | }
170 |
171 | - (MASViewAttribute *)mas_safeAreaLayoutGuideCenterY {
172 | return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeCenterY];
173 | }
174 |
175 | #endif
176 |
177 | #pragma mark - associated properties
178 |
179 | - (id)mas_key {
180 | return objc_getAssociatedObject(self, @selector(mas_key));
181 | }
182 |
183 | - (void)setMas_key:(id)key {
184 | objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
185 | }
186 |
187 | #pragma mark - heirachy
188 |
189 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view {
190 | MAS_VIEW *closestCommonSuperview = nil;
191 |
192 | MAS_VIEW *secondViewSuperview = view;
193 | while (!closestCommonSuperview && secondViewSuperview) {
194 | MAS_VIEW *firstViewSuperview = self;
195 | while (!closestCommonSuperview && firstViewSuperview) {
196 | if (secondViewSuperview == firstViewSuperview) {
197 | closestCommonSuperview = secondViewSuperview;
198 | }
199 | firstViewSuperview = firstViewSuperview.superview;
200 | }
201 | secondViewSuperview = secondViewSuperview.superview;
202 | }
203 | return closestCommonSuperview;
204 | }
205 |
206 | @end
207 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/View+MASShorthandAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASShorthandAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "View+MASAdditions.h"
10 |
11 | #ifdef MAS_SHORTHAND
12 |
13 | /**
14 | * Shorthand view additions without the 'mas_' prefixes,
15 | * only enabled if MAS_SHORTHAND is defined
16 | */
17 | @interface MAS_VIEW (MASShorthandAdditions)
18 |
19 | @property (nonatomic, strong, readonly) MASViewAttribute *left;
20 | @property (nonatomic, strong, readonly) MASViewAttribute *top;
21 | @property (nonatomic, strong, readonly) MASViewAttribute *right;
22 | @property (nonatomic, strong, readonly) MASViewAttribute *bottom;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *leading;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *trailing;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *width;
26 | @property (nonatomic, strong, readonly) MASViewAttribute *height;
27 | @property (nonatomic, strong, readonly) MASViewAttribute *centerX;
28 | @property (nonatomic, strong, readonly) MASViewAttribute *centerY;
29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline;
30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr);
31 |
32 | @property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline;
33 | @property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline;
34 |
35 | #if TARGET_OS_IPHONE || TARGET_OS_TV
36 |
37 | @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin;
38 | @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin;
39 | @property (nonatomic, strong, readonly) MASViewAttribute *topMargin;
40 | @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin;
41 | @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin;
42 | @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin;
43 | @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins;
44 | @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins;
45 |
46 | #endif
47 |
48 | #if TARGET_OS_IPHONE || TARGET_OS_TV
49 |
50 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeading NS_AVAILABLE_IOS(11.0);
51 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTrailing NS_AVAILABLE_IOS(11.0);
52 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideLeft NS_AVAILABLE_IOS(11.0);
53 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideRight NS_AVAILABLE_IOS(11.0);
54 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideTop NS_AVAILABLE_IOS(11.0);
55 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideBottom NS_AVAILABLE_IOS(11.0);
56 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideWidth NS_AVAILABLE_IOS(11.0);
57 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideHeight NS_AVAILABLE_IOS(11.0);
58 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
59 | @property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);
60 |
61 | #endif
62 |
63 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
64 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
65 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
66 |
67 | @end
68 |
69 | #define MAS_ATTR_FORWARD(attr) \
70 | - (MASViewAttribute *)attr { \
71 | return [self mas_##attr]; \
72 | }
73 |
74 | #define MAS_ATTR_FORWARD_AVAILABLE(attr, available) \
75 | - (MASViewAttribute *)attr available { \
76 | return [self mas_##attr]; \
77 | }
78 |
79 | @implementation MAS_VIEW (MASShorthandAdditions)
80 |
81 | MAS_ATTR_FORWARD(top);
82 | MAS_ATTR_FORWARD(left);
83 | MAS_ATTR_FORWARD(bottom);
84 | MAS_ATTR_FORWARD(right);
85 | MAS_ATTR_FORWARD(leading);
86 | MAS_ATTR_FORWARD(trailing);
87 | MAS_ATTR_FORWARD(width);
88 | MAS_ATTR_FORWARD(height);
89 | MAS_ATTR_FORWARD(centerX);
90 | MAS_ATTR_FORWARD(centerY);
91 | MAS_ATTR_FORWARD(baseline);
92 |
93 | MAS_ATTR_FORWARD(firstBaseline);
94 | MAS_ATTR_FORWARD(lastBaseline);
95 |
96 | #if TARGET_OS_IPHONE || TARGET_OS_TV
97 |
98 | MAS_ATTR_FORWARD(leftMargin);
99 | MAS_ATTR_FORWARD(rightMargin);
100 | MAS_ATTR_FORWARD(topMargin);
101 | MAS_ATTR_FORWARD(bottomMargin);
102 | MAS_ATTR_FORWARD(leadingMargin);
103 | MAS_ATTR_FORWARD(trailingMargin);
104 | MAS_ATTR_FORWARD(centerXWithinMargins);
105 | MAS_ATTR_FORWARD(centerYWithinMargins);
106 |
107 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeading, NS_AVAILABLE_IOS(11.0));
108 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTrailing, NS_AVAILABLE_IOS(11.0));
109 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideLeft, NS_AVAILABLE_IOS(11.0));
110 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideRight, NS_AVAILABLE_IOS(11.0));
111 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideTop, NS_AVAILABLE_IOS(11.0));
112 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideBottom, NS_AVAILABLE_IOS(11.0));
113 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideWidth, NS_AVAILABLE_IOS(11.0));
114 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideHeight, NS_AVAILABLE_IOS(11.0));
115 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterX, NS_AVAILABLE_IOS(11.0));
116 | MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterY, NS_AVAILABLE_IOS(11.0));
117 |
118 | #endif
119 |
120 | - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
121 | return [self mas_attribute];
122 | }
123 |
124 | - (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
125 | return [self mas_makeConstraints:block];
126 | }
127 |
128 | - (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
129 | return [self mas_updateConstraints:block];
130 | }
131 |
132 | - (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(MASConstraintMaker *))block {
133 | return [self mas_remakeConstraints:block];
134 | }
135 |
136 | @end
137 |
138 | #endif
139 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/ViewController+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewController+MASAdditions.h
3 | // Masonry
4 | //
5 | // Created by Craig Siemens on 2015-06-23.
6 | //
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | #ifdef MAS_VIEW_CONTROLLER
14 |
15 | @interface MAS_VIEW_CONTROLLER (MASAdditions)
16 |
17 | /**
18 | * following properties return a new MASViewAttribute with appropriate UILayoutGuide and NSLayoutAttribute
19 | */
20 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide NS_DEPRECATED_IOS(8.0, 11.0);
21 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide NS_DEPRECATED_IOS(8.0, 11.0);
22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop NS_DEPRECATED_IOS(8.0, 11.0);
23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom NS_DEPRECATED_IOS(8.0, 11.0);
24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop NS_DEPRECATED_IOS(8.0, 11.0);
25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom NS_DEPRECATED_IOS(8.0, 11.0);
26 |
27 | @end
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/Masonry/ViewController+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewController+MASAdditions.m
3 | // Masonry
4 | //
5 | // Created by Craig Siemens on 2015-06-23.
6 | //
7 | //
8 |
9 | #import "ViewController+MASAdditions.h"
10 |
11 | #ifdef MAS_VIEW_CONTROLLER
12 |
13 | @implementation MAS_VIEW_CONTROLLER (MASAdditions)
14 |
15 | #pragma clang diagnostic push
16 | #pragma clang diagnostic ignored "-Wdeprecated-declarations"
17 |
18 | - (MASViewAttribute *)mas_topLayoutGuide {
19 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
20 | }
21 | - (MASViewAttribute *)mas_topLayoutGuideTop {
22 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeTop];
23 | }
24 | - (MASViewAttribute *)mas_topLayoutGuideBottom {
25 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
26 | }
27 |
28 | - (MASViewAttribute *)mas_bottomLayoutGuide {
29 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop];
30 | }
31 | - (MASViewAttribute *)mas_bottomLayoutGuideTop {
32 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop];
33 | }
34 | - (MASViewAttribute *)mas_bottomLayoutGuideBottom {
35 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
36 | }
37 |
38 | #pragma clang diagnostic pop
39 |
40 | @end
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // ZZCircleProgressDemo
4 | //
5 | // Created by iMac on 2016/12/23.
6 | // Copyright © 2016年 zhouxing. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // ZZCircleProgressDemo
4 | //
5 | // Created by iMac on 2016/12/23.
6 | // Copyright © 2016年 zhouxing. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "ZZCircleProgress.h"
11 | #import "Masonry.h"
12 |
13 | @interface ViewController ()
14 |
15 | @property (strong, nonatomic) ZZCircleProgress *progressView;
16 |
17 |
18 | @property (weak, nonatomic) IBOutlet UILabel *startAngleLabel;
19 | @property (weak, nonatomic) IBOutlet UILabel *reduceAngleLabel;
20 | @property (weak, nonatomic) IBOutlet UILabel *strokeWidthLabel;
21 | @property (weak, nonatomic) IBOutlet UILabel *durationLabel;
22 |
23 | @end
24 |
25 | @implementation ViewController
26 |
27 | - (void)viewDidLoad {
28 | [super viewDidLoad];
29 |
30 | //1.添加进度条frame
31 | // [self addProgressViewByFrame];
32 |
33 | //2.添加进度条autolayout
34 | [self addProgressViewByAutoLayout];
35 | }
36 |
37 | //frame
38 | - (void)addProgressViewByFrame {
39 | self.progressView = [[ZZCircleProgress alloc] initWithFrame:CGRectMake((CGRectGetWidth(self.view.frame)-240)/2.0, 42, 240, 240) pathBackColor:[UIColor lightGrayColor] pathFillColor:[UIColor redColor] startAngle:0 strokeWidth:10];
40 | [self.view addSubview:self.progressView];
41 | }
42 |
43 | //autolayout
44 | - (void)addProgressViewByAutoLayout {
45 | // self.progressView = [[ZZCircleProgress alloc] init];
46 | self.progressView = [[ZZCircleProgress alloc] initWithFrame:CGRectZero pathBackColor:[UIColor grayColor] pathFillColor:[UIColor greenColor] startAngle:0 strokeWidth:20];
47 | self.progressView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3];
48 | [self.view addSubview:self.progressView];
49 |
50 | [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
51 | make.top.mas_equalTo(self.view).offset(42);
52 | make.left.mas_equalTo(self.view).offset(120);
53 | make.right.mas_equalTo(self.view).offset(-120);
54 | make.bottom.mas_equalTo(self.view.mas_top).offset(300);
55 | }];
56 | }
57 |
58 |
59 | //改变开始角度
60 | - (IBAction)startAngleChanged:(UISlider *)sender {
61 |
62 | self.progressView.startAngle = sender.value;
63 | self.startAngleLabel.text = [NSString stringWithFormat:@"%d",(int)sender.value];
64 | }
65 |
66 | //改变减少角度
67 | - (IBAction)reduceAngleChanged:(UISlider *)sender {
68 |
69 | self.progressView.reduceAngle = sender.value;
70 | self.reduceAngleLabel.text = [NSString stringWithFormat:@"%d",(int)sender.value];
71 | }
72 |
73 | //改变线宽
74 | - (IBAction)srokeWidthChanged:(UISlider *)sender {
75 |
76 | self.progressView.strokeWidth = sender.value;
77 | self.strokeWidthLabel.text = [NSString stringWithFormat:@"%d",(int)sender.value];
78 | }
79 |
80 | //改变动画时长
81 | - (IBAction)animationDurationChanged:(UISlider *)sender {
82 |
83 | self.progressView.duration = sender.value;
84 | self.durationLabel.text = [NSString stringWithFormat:@"%.1f",sender.value];
85 | }
86 |
87 |
88 | //是否显示圆点
89 | - (IBAction)showPointChanged:(UISwitch *)sender {
90 |
91 | self.progressView.showPoint = sender.isOn;
92 | }
93 |
94 | //是否显示进度文本
95 | - (IBAction)showTextChanged:(UISwitch *)sender {
96 |
97 | self.progressView.showProgressText = sender.isOn;
98 | }
99 |
100 | //进度是否从头开始
101 | - (IBAction)increaseFromLastChanged:(UISwitch *)sender {
102 |
103 | self.progressView.increaseFromLast = sender.isOn;
104 | }
105 |
106 | //生成随机进度
107 | - (IBAction)createProgress:(id)sender {
108 |
109 | self.progressView.progress = arc4random()%101/100.0;
110 |
111 | //随机填充色
112 | self.progressView.pathFillColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
113 | }
114 |
115 | @end
116 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.bundle/circle_point1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.bundle/circle_point1.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.bundle/circle_point2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.bundle/circle_point2.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.bundle/circle_point3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.bundle/circle_point3.png
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.h:
--------------------------------------------------------------------------------
1 | //
2 | // ZZCircleProgress.h
3 | // ZZCircleProgressDemo
4 | //
5 | // Created by 周兴 on 2018/5/16.
6 | // Copyright © 2018年 zhouxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "ZZCountingLabel.h"
11 |
12 | #define ZZCircleDegreeToRadian(d) ((d)*M_PI)/180.0
13 | #define ZZCircleRGB(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
14 | #define ZZCircleSelfWidth self.frame.size.width
15 | #define ZZCircleSelfHeight self.frame.size.height
16 |
17 | @interface ZZCircleProgress : UIView
18 |
19 | //图形定制
20 | @property (nonatomic, strong) UIColor *pathBackColor;/**<线条背景色*/
21 | @property (nonatomic, strong) UIColor *pathFillColor;/**<线条填充色*/
22 | @property (nonatomic, strong) UIImageView *pointImage;/**<小圆点图片*/
23 | @property (nonatomic, strong) ZZCountingLabel *progressLabel;
24 |
25 | //角度相关
26 | @property (nonatomic, assign) CGFloat startAngle;/**<起点角度。角度从水平右侧开始为0,顺时针为增加角度。直接传度数 如-90 */
27 | @property (nonatomic, assign) CGFloat reduceAngle;/**<减少的角度 直接传度数 如30*/
28 | @property (nonatomic, assign) CGFloat strokeWidth;/**<线宽*/
29 |
30 | @property (nonatomic, assign) CGFloat duration;/**<动画时长*/
31 |
32 | @property (nonatomic, assign) BOOL showPoint;/**<是否显示小圆点*/
33 | @property (nonatomic, assign) BOOL showProgressText;/**<是否显示文字*/
34 | @property (nonatomic, assign) BOOL increaseFromLast;/**<是否从上次数值开始动画,默认为NO*/
35 |
36 | //进度
37 | @property (nonatomic, assign) CGFloat progress;/**<进度 0-1 */
38 |
39 | /**
40 | 初始化
41 |
42 | @param frame 使用自动布局时传CGRectZero
43 | @param pathBackColor 背景线条色
44 | @param pathFillColor 填充线条色
45 | @param startAngle 开始角度
46 | @param strokeWidth 线条宽度
47 | @return ZZCircleProgress
48 | */
49 | - (instancetype)initWithFrame:(CGRect)frame
50 | pathBackColor:(UIColor *)pathBackColor
51 | pathFillColor:(UIColor *)pathFillColor
52 | startAngle:(CGFloat)startAngle
53 | strokeWidth:(CGFloat)strokeWidth;
54 |
55 | @end
56 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ZZCircleProgress/ZZCircleProgress.m:
--------------------------------------------------------------------------------
1 | //
2 | // ZZCircleProgress.m
3 | // ZZCircleProgressDemo
4 | //
5 | // Created by 周兴 on 2018/5/16.
6 | // Copyright © 2018年 zhouxing. All rights reserved.
7 | //
8 |
9 | #import "ZZCircleProgress.h"
10 |
11 | @interface ZZCircleProgress ()
12 |
13 | @property (nonatomic, strong) CAShapeLayer *backLayer;
14 | @property (nonatomic, strong) CAShapeLayer *progressLayer;
15 |
16 | @property (nonatomic, assign) CGFloat realWidth;//实际边长
17 | @property (nonatomic, assign) CGFloat radius;//半径
18 | @property (nonatomic, assign) CGFloat lastProgress;/**<上次进度 0-1 */
19 | @property (nonatomic, strong) CAAnimation *lastPointAnimation;
20 |
21 | @end
22 |
23 |
24 | @implementation ZZCircleProgress
25 |
26 | - (instancetype)init {
27 | if (self = [super init]) {
28 | [self initialization];
29 | }
30 | return self;
31 | }
32 |
33 | - (instancetype)initWithFrame:(CGRect)frame {
34 | if (self = [super initWithFrame:frame]) {
35 | [self initialization];
36 | }
37 | return self;
38 | }
39 |
40 | - (void)awakeFromNib {
41 | [super awakeFromNib];
42 | [self initialization];
43 | }
44 |
45 | //初始化
46 | - (instancetype)initWithFrame:(CGRect)frame
47 | pathBackColor:(UIColor *)pathBackColor
48 | pathFillColor:(UIColor *)pathFillColor
49 | startAngle:(CGFloat)startAngle
50 | strokeWidth:(CGFloat)strokeWidth {
51 | if (self = [super initWithFrame:frame]) {
52 | [self initialization];
53 | self.pathBackColor = pathBackColor;
54 | self.pathFillColor = pathFillColor;
55 | _startAngle = ZZCircleDegreeToRadian(startAngle);
56 | _strokeWidth = strokeWidth;
57 | }
58 | return self;
59 | }
60 |
61 | //初始化数据
62 | - (void)initialization {
63 | self.backgroundColor = [UIColor clearColor];
64 | _pathBackColor = [UIColor lightGrayColor];
65 | _pathFillColor = [UIColor redColor];
66 |
67 | _strokeWidth = 10;//线宽默认为10
68 | _startAngle = ZZCircleDegreeToRadian(0);//圆起点位置
69 | _reduceAngle = ZZCircleDegreeToRadian(0);//整个圆缺少的角度
70 |
71 | _duration = 1.5;//动画时长
72 | _showPoint = YES;//小圆点
73 | _showProgressText = YES;//文字
74 |
75 | //初始化layer
76 | [self initSubviews];
77 | }
78 |
79 | #pragma Get
80 | - (CAShapeLayer *)backLayer {
81 | if (!_backLayer) {
82 | _backLayer = [CAShapeLayer layer];
83 | _backLayer.fillColor = [UIColor clearColor].CGColor;//填充色
84 | _backLayer.lineWidth = _strokeWidth;
85 | _backLayer.strokeColor = _pathBackColor.CGColor;
86 | _backLayer.lineCap = @"round";
87 | }
88 | return _backLayer;
89 | }
90 |
91 | - (CAShapeLayer *)progressLayer {
92 | if (!_progressLayer) {
93 | _progressLayer = [CAShapeLayer layer];
94 | _progressLayer.fillColor = [UIColor clearColor].CGColor;//填充色
95 | _progressLayer.lineWidth = _strokeWidth;
96 | _progressLayer.strokeColor = _pathFillColor.CGColor;
97 | _progressLayer.lineCap = @"round";
98 | }
99 | return _progressLayer;
100 | }
101 |
102 | - (UIImageView *)pointImage {
103 | if (!_pointImage) {
104 | _pointImage = [[UIImageView alloc] init];
105 |
106 | NSBundle *mainBundle = [NSBundle bundleForClass:[self class]];
107 | NSBundle *resourcesBundle = [NSBundle bundleWithPath:[mainBundle pathForResource:@"ZZCircleProgress" ofType:@"bundle"]];
108 | _pointImage.image = [UIImage imageNamed:@"circle_point1" inBundle:resourcesBundle compatibleWithTraitCollection:nil];
109 | }
110 | return _pointImage;
111 | }
112 |
113 | - (ZZCountingLabel *)progressLabel {
114 | if (!_progressLabel) {
115 | _progressLabel = [[ZZCountingLabel alloc] init];
116 | _progressLabel.textColor = [UIColor blackColor];
117 | _progressLabel.textAlignment = NSTextAlignmentCenter;
118 | _progressLabel.font = [UIFont systemFontOfSize:22];
119 | _progressLabel.text = @"0%";
120 | }
121 | return _progressLabel;
122 | }
123 |
124 | - (CAAnimation *)pathAnimation {
125 | CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
126 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
127 | pathAnimation.duration = _duration;
128 | pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
129 | pathAnimation.fromValue = [NSNumber numberWithFloat:_increaseFromLast==YES?_lastProgress:0];
130 | pathAnimation.toValue = [NSNumber numberWithFloat:_progress];
131 | pathAnimation.fillMode = kCAFillModeForwards;
132 | pathAnimation.removedOnCompletion = NO;
133 | return pathAnimation;
134 | }
135 |
136 | - (CAAnimation *)pointAnimation {
137 | CAKeyframeAnimation *pointAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
138 | pointAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
139 | pointAnimation.fillMode = kCAFillModeForwards;
140 | pointAnimation.calculationMode = @"paced";
141 | pointAnimation.removedOnCompletion = NO;
142 | pointAnimation.duration = _duration;
143 | pointAnimation.delegate = self;
144 |
145 | BOOL clockwise = NO;
146 | if (_progress<_lastProgress && _increaseFromLast == YES) {
147 | clockwise = YES;
148 | }
149 | UIBezierPath *imagePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(_realWidth/2.0, _realWidth/2.0) radius:_radius startAngle:_increaseFromLast==YES?(2*M_PI-_reduceAngle)*_lastProgress+_startAngle:_startAngle endAngle:(2*M_PI-_reduceAngle)*_progress+_startAngle clockwise:!clockwise];
150 | pointAnimation.path = imagePath.CGPath;
151 |
152 | return pointAnimation;
153 | }
154 |
155 | #pragma Set
156 | - (void)setStartAngle:(CGFloat)startAngle {
157 | if (_startAngle != ZZCircleDegreeToRadian(startAngle)) {
158 | _startAngle = ZZCircleDegreeToRadian(startAngle);
159 | [self setNeedsLayout];
160 | }
161 | }
162 |
163 | - (void)setReduceAngle:(CGFloat)reduceAngle {
164 | if (_reduceAngle != ZZCircleDegreeToRadian(reduceAngle)) {
165 | if (reduceAngle>=360) {
166 | return;
167 | }
168 | _reduceAngle = ZZCircleDegreeToRadian(reduceAngle);
169 | [self setNeedsLayout];
170 | }
171 | }
172 |
173 | - (void)setStrokeWidth:(CGFloat)strokeWidth {
174 | if (_strokeWidth != strokeWidth) {
175 | _strokeWidth = strokeWidth;
176 | _radius = _realWidth/2.0 - _strokeWidth/2.0;
177 | [self setNeedsLayout];
178 | }
179 | }
180 |
181 | - (void)setPathBackColor:(UIColor *)pathBackColor {
182 | if (_pathBackColor != pathBackColor) {
183 | _pathBackColor = pathBackColor;
184 | self.backLayer.strokeColor = _pathBackColor.CGColor;
185 | }
186 | }
187 |
188 | - (void)setPathFillColor:(UIColor *)pathFillColor {
189 | if (_pathFillColor != pathFillColor) {
190 | _pathFillColor = pathFillColor;
191 | self.progressLayer.strokeColor = _pathFillColor.CGColor;
192 | }
193 | }
194 |
195 | - (void)setShowPoint:(BOOL)showPoint {
196 | if (_showPoint != showPoint) {
197 | _showPoint = showPoint;
198 | if (_showPoint) {
199 | self.pointImage.hidden = NO;
200 | [self updatePointPosition];
201 | } else {
202 | self.pointImage.hidden = YES;
203 | }
204 | }
205 | }
206 |
207 | -(void)setShowProgressText:(BOOL)showProgressText {
208 | if (_showProgressText != showProgressText) {
209 | _showProgressText = showProgressText;
210 | if (_showProgressText) {
211 | self.progressLabel.hidden = NO;
212 | } else {
213 | self.progressLabel.hidden = YES;
214 | }
215 | }
216 | }
217 |
218 | - (void)setProgress:(CGFloat)progress {
219 | _progress = MAX(MIN(1, progress), 0);
220 |
221 | dispatch_async(dispatch_get_main_queue(), ^{
222 | [self startAnimation];
223 | });
224 | }
225 |
226 | #pragma Methods
227 | - (void)startAnimation {
228 |
229 | [self.progressLayer addAnimation:[self pathAnimation] forKey:@"strokeEndAnimation"];
230 |
231 | if (_showPoint) {
232 | CAAnimation *pointAnimation = [self pointAnimation];
233 | [self.pointImage.layer addAnimation:pointAnimation forKey:@"pointAnimation"];
234 | self.lastPointAnimation = pointAnimation;
235 |
236 | if (!_increaseFromLast && _progress == 0.0) {
237 | [self.pointImage.layer removeAllAnimations];
238 | }
239 | }
240 |
241 | if (_showProgressText && _increaseFromLast) {
242 | [self.progressLabel countingFrom:_lastProgress*100 to:_progress*100 duration:_duration];
243 | } else if (_showProgressText) {
244 | [self.progressLabel countingFrom:0 to:_progress*100 duration:_duration];
245 | }
246 |
247 | _lastProgress = _progress;
248 | }
249 |
250 | - (UIBezierPath *)getNewBezierPath {
251 | return [UIBezierPath bezierPathWithArcCenter:CGPointMake(_realWidth/2.0, _realWidth/2.0) radius:_radius startAngle:_startAngle endAngle:(2*M_PI-_reduceAngle+_startAngle) clockwise:YES];
252 | }
253 |
254 | - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
255 | if (flag && anim == [self.pointImage.layer animationForKey:@"pointAnimation"]) {
256 | [self updatePointPosition];
257 | }
258 | }
259 |
260 | - (void)updatePointPosition {
261 | CGFloat currentEndAngle = (2*M_PI-_reduceAngle)*_progress+_startAngle;
262 | [_pointImage.layer removeAllAnimations];
263 | _pointImage.center = CGPointMake(_realWidth/2.0+_radius*cosf(currentEndAngle), _realWidth/2.0+_radius*sinf(currentEndAngle));
264 | }
265 |
266 | #pragma initSubviews
267 | - (void)initSubviews {
268 | [self.layer addSublayer:self.backLayer];
269 | [self.layer addSublayer:self.progressLayer];
270 |
271 | [self addSubview:self.pointImage];
272 | [self addSubview:self.progressLabel];
273 | }
274 |
275 | #pragma layout
276 | - (void)layoutSubviews {
277 | [super layoutSubviews];
278 |
279 | self.realWidth = MIN(ZZCircleSelfWidth, ZZCircleSelfHeight);
280 | self.radius = _realWidth/2.0 - _strokeWidth/2.0;
281 |
282 | self.backLayer.frame = CGRectMake(0, 0, _realWidth, _realWidth);
283 | self.backLayer.lineWidth = _strokeWidth;
284 | self.backLayer.path = [self getNewBezierPath].CGPath;
285 |
286 | self.progressLayer.frame = CGRectMake(0, 0, _realWidth, _realWidth);
287 | self.progressLayer.lineWidth = _strokeWidth;
288 | self.progressLayer.path = [self getNewBezierPath].CGPath;
289 | self.progressLayer.strokeEnd = 0.0;
290 |
291 | self.progressLabel.frame = CGRectMake(0, 0, _realWidth, _realWidth);
292 |
293 | self.pointImage.frame = CGRectMake(0, 0, _strokeWidth, _strokeWidth);
294 | [self updatePointPosition];
295 |
296 | }
297 |
298 | @end
299 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ZZCircleProgress/ZZCountingLabel.h:
--------------------------------------------------------------------------------
1 | //
2 | // ZZCountingLabel.h
3 | // 动画测试
4 | //
5 | // Created by 周兴 on 2017/6/29.
6 | // Copyright © 2017年 周兴. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ZZCountingLabel : UILabel
12 |
13 | @property (nonatomic, assign) CGFloat duration;
14 |
15 | - (void)countingFrom:(CGFloat)fromValue to:(CGFloat)toValue;
16 | - (void)countingFrom:(CGFloat)fromValue to:(CGFloat)toValue duration:(CGFloat)duration;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/ZZCircleProgress/ZZCountingLabel.m:
--------------------------------------------------------------------------------
1 | //
2 | // ZZCountingLabel.m
3 | // 动画测试
4 | //
5 | // Created by 周兴 on 2017/6/29.
6 | // Copyright © 2017年 周兴. All rights reserved.
7 | //
8 |
9 | #import "ZZCountingLabel.h"
10 |
11 | @interface ZZCountingLabel ()
12 |
13 | @property (nonatomic, strong) CADisplayLink *playLink;
14 | @property (nonatomic, assign) NSInteger displayPerSecond;
15 |
16 | @property (nonatomic, assign) CGFloat fromValue;
17 | @property (nonatomic, assign) CGFloat toValue;
18 |
19 | @property (nonatomic, assign) CGFloat increaseValue;
20 | @property (nonatomic, assign) CGFloat perValue;
21 |
22 | @end
23 |
24 | @implementation ZZCountingLabel
25 |
26 | - (instancetype)init {
27 | if (self = [super init]) {
28 | [self initValues];
29 | }
30 | return self;
31 | }
32 |
33 | - (instancetype)initWithFrame:(CGRect)frame {
34 | if (self = [super initWithFrame:frame]) {
35 | [self initValues];
36 | }
37 | return self;
38 | }
39 |
40 | - (void)awakeFromNib {
41 | [super awakeFromNib];
42 | [self initValues];
43 | }
44 |
45 | - (void)initValues {
46 | _duration = 2.0;
47 | _displayPerSecond = 30;
48 | }
49 |
50 | - (void)countingFrom:(CGFloat)fromValue to:(CGFloat)toValue {
51 | [self countingFrom:fromValue to:toValue duration:_duration];
52 | }
53 |
54 | - (void)countingFrom:(CGFloat)fromValue to:(CGFloat)toValue duration:(CGFloat)duration {
55 |
56 | _fromValue = fromValue;
57 | _toValue = toValue;
58 | _duration = duration;
59 |
60 | _increaseValue = _fromValue;
61 | _perValue = (_toValue - _fromValue)/(_duration==0?1:(_displayPerSecond*_duration));
62 |
63 | if (self.playLink) {
64 | [self.playLink invalidate];
65 | self.playLink = nil;
66 | }
67 |
68 | CADisplayLink *playLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(countingAction)];
69 | if (@available(iOS 10.0, *)) {
70 | playLink.preferredFramesPerSecond = _displayPerSecond;
71 | } else {
72 | playLink.frameInterval = 60/(_displayPerSecond==0?1:_displayPerSecond);
73 | }
74 |
75 | [playLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
76 | [playLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:UITrackingRunLoopMode];
77 | self.playLink = playLink;
78 |
79 | }
80 |
81 | - (void)countingAction {
82 | _increaseValue += _perValue;
83 |
84 | if (_fromValue < _toValue) {
85 | if (_increaseValue >= _toValue) {
86 | [self stopDisplayLink];
87 | }
88 | } else {
89 | if (_increaseValue <= _toValue) {
90 | [self stopDisplayLink];
91 | }
92 | }
93 |
94 | dispatch_async(dispatch_get_main_queue(), ^{
95 | self.text = [NSString stringWithFormat:@"%.0f%%",_increaseValue];
96 | });
97 | }
98 |
99 | - (void)stopDisplayLink {
100 |
101 | [self.playLink invalidate];
102 | self.playLink = nil;
103 |
104 | _increaseValue = _toValue;
105 | }
106 |
107 | @end
108 |
--------------------------------------------------------------------------------
/ZZCircleProgressDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // ZZCircleProgressDemo
4 | //
5 | // Created by iMac on 2016/12/23.
6 | // Copyright © 2016年 zhouxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ZZCircleProgress_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgress_demo.gif
--------------------------------------------------------------------------------
/ZZCircleProgress_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhouxing5311/ZZCircleProgress/98e330eb4594b50cae2631cd15e75d4220a6943c/ZZCircleProgress_logo.png
--------------------------------------------------------------------------------