├── .gitignore
├── LICENSE
├── README.md
├── RatingBar.xcodeproj
├── project.pbxproj
└── project.xcworkspace
│ └── contents.xcworkspacedata
├── RatingBar
├── AppDelegate.swift
├── Base.lproj
│ ├── LaunchScreen.xib
│ └── Main.storyboard
├── Images.xcassets
│ ├── AppIcon.appiconset
│ │ └── Contents.json
│ ├── ic_ratingbar_star_dark.imageset
│ │ ├── Contents.json
│ │ └── ic_ratingbar_star_dark@3x.png
│ └── ic_ratingbar_star_light.imageset
│ │ ├── Contents.json
│ │ └── ic_ratingbar_star_light@3x.png
├── Info.plist
├── RatingBar.swift
└── ViewController.swift
├── RatingBarTests
├── Info.plist
└── RatingBarTests.swift
└── preview
└── ratingbardemo.gif
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | build/
4 | *.pbxuser
5 | !default.pbxuser
6 | *.mode1v3
7 | !default.mode1v3
8 | *.mode2v3
9 | !default.mode2v3
10 | *.perspectivev3
11 | !default.perspectivev3
12 | xcuserdata
13 | *.xccheckout
14 | *.moved-aside
15 | DerivedData
16 | *.hmap
17 | *.ipa
18 | *.xcuserstate
19 |
20 | # CocoaPods
21 | #
22 | # We recommend against adding the Pods directory to your .gitignore. However
23 | # you should judge for yourself, the pros and cons are mentioned at:
24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
25 | #
26 | # Pods/
27 |
28 | # Carthage
29 | #
30 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
31 | # Carthage/Checkouts
32 |
33 | Carthage/Build
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # iOS-RatingBar swift版的评分控件
2 | ### 描述
3 | 跟Android的RatingBar一样有两种模式,评分模式和只读模式
4 | 支持视图编辑,自定义星星数量,评分等级
5 | 另外还能支持非整数星,0.5颗星,0.1颗星
6 | 可以开启动画效果
7 | ### Demo
8 |
9 | 
10 |
--------------------------------------------------------------------------------
/RatingBar.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 327E5B0A1AE753E40086FAF0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 327E5B091AE753E40086FAF0 /* AppDelegate.swift */; };
11 | 327E5B0C1AE753E40086FAF0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 327E5B0B1AE753E40086FAF0 /* ViewController.swift */; };
12 | 327E5B0F1AE753E40086FAF0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 327E5B0D1AE753E40086FAF0 /* Main.storyboard */; };
13 | 327E5B111AE753E40086FAF0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 327E5B101AE753E40086FAF0 /* Images.xcassets */; };
14 | 327E5B141AE753E40086FAF0 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 327E5B121AE753E40086FAF0 /* LaunchScreen.xib */; };
15 | 327E5B201AE753E40086FAF0 /* RatingBarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 327E5B1F1AE753E40086FAF0 /* RatingBarTests.swift */; };
16 | 327E5B2A1AE773C10086FAF0 /* RatingBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 327E5B291AE773C10086FAF0 /* RatingBar.swift */; };
17 | /* End PBXBuildFile section */
18 |
19 | /* Begin PBXContainerItemProxy section */
20 | 327E5B1A1AE753E40086FAF0 /* PBXContainerItemProxy */ = {
21 | isa = PBXContainerItemProxy;
22 | containerPortal = 327E5AFC1AE753E40086FAF0 /* Project object */;
23 | proxyType = 1;
24 | remoteGlobalIDString = 327E5B031AE753E40086FAF0;
25 | remoteInfo = RatingBar;
26 | };
27 | /* End PBXContainerItemProxy section */
28 |
29 | /* Begin PBXFileReference section */
30 | 327E5B041AE753E40086FAF0 /* RatingBar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RatingBar.app; sourceTree = BUILT_PRODUCTS_DIR; };
31 | 327E5B081AE753E40086FAF0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
32 | 327E5B091AE753E40086FAF0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
33 | 327E5B0B1AE753E40086FAF0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
34 | 327E5B0E1AE753E40086FAF0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
35 | 327E5B101AE753E40086FAF0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
36 | 327E5B131AE753E40086FAF0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; };
37 | 327E5B191AE753E40086FAF0 /* RatingBarTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RatingBarTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
38 | 327E5B1E1AE753E40086FAF0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
39 | 327E5B1F1AE753E40086FAF0 /* RatingBarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RatingBarTests.swift; sourceTree = ""; };
40 | 327E5B291AE773C10086FAF0 /* RatingBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RatingBar.swift; sourceTree = ""; };
41 | /* End PBXFileReference section */
42 |
43 | /* Begin PBXFrameworksBuildPhase section */
44 | 327E5B011AE753E40086FAF0 /* Frameworks */ = {
45 | isa = PBXFrameworksBuildPhase;
46 | buildActionMask = 2147483647;
47 | files = (
48 | );
49 | runOnlyForDeploymentPostprocessing = 0;
50 | };
51 | 327E5B161AE753E40086FAF0 /* Frameworks */ = {
52 | isa = PBXFrameworksBuildPhase;
53 | buildActionMask = 2147483647;
54 | files = (
55 | );
56 | runOnlyForDeploymentPostprocessing = 0;
57 | };
58 | /* End PBXFrameworksBuildPhase section */
59 |
60 | /* Begin PBXGroup section */
61 | 327E5AFB1AE753E40086FAF0 = {
62 | isa = PBXGroup;
63 | children = (
64 | 327E5B061AE753E40086FAF0 /* RatingBar */,
65 | 327E5B1C1AE753E40086FAF0 /* RatingBarTests */,
66 | 327E5B051AE753E40086FAF0 /* Products */,
67 | );
68 | sourceTree = "";
69 | };
70 | 327E5B051AE753E40086FAF0 /* Products */ = {
71 | isa = PBXGroup;
72 | children = (
73 | 327E5B041AE753E40086FAF0 /* RatingBar.app */,
74 | 327E5B191AE753E40086FAF0 /* RatingBarTests.xctest */,
75 | );
76 | name = Products;
77 | sourceTree = "";
78 | };
79 | 327E5B061AE753E40086FAF0 /* RatingBar */ = {
80 | isa = PBXGroup;
81 | children = (
82 | 327E5B091AE753E40086FAF0 /* AppDelegate.swift */,
83 | 327E5B0B1AE753E40086FAF0 /* ViewController.swift */,
84 | 327E5B0D1AE753E40086FAF0 /* Main.storyboard */,
85 | 327E5B101AE753E40086FAF0 /* Images.xcassets */,
86 | 327E5B121AE753E40086FAF0 /* LaunchScreen.xib */,
87 | 327E5B071AE753E40086FAF0 /* Supporting Files */,
88 | 327E5B291AE773C10086FAF0 /* RatingBar.swift */,
89 | );
90 | path = RatingBar;
91 | sourceTree = "";
92 | };
93 | 327E5B071AE753E40086FAF0 /* Supporting Files */ = {
94 | isa = PBXGroup;
95 | children = (
96 | 327E5B081AE753E40086FAF0 /* Info.plist */,
97 | );
98 | name = "Supporting Files";
99 | sourceTree = "";
100 | };
101 | 327E5B1C1AE753E40086FAF0 /* RatingBarTests */ = {
102 | isa = PBXGroup;
103 | children = (
104 | 327E5B1F1AE753E40086FAF0 /* RatingBarTests.swift */,
105 | 327E5B1D1AE753E40086FAF0 /* Supporting Files */,
106 | );
107 | path = RatingBarTests;
108 | sourceTree = "";
109 | };
110 | 327E5B1D1AE753E40086FAF0 /* Supporting Files */ = {
111 | isa = PBXGroup;
112 | children = (
113 | 327E5B1E1AE753E40086FAF0 /* Info.plist */,
114 | );
115 | name = "Supporting Files";
116 | sourceTree = "";
117 | };
118 | /* End PBXGroup section */
119 |
120 | /* Begin PBXNativeTarget section */
121 | 327E5B031AE753E40086FAF0 /* RatingBar */ = {
122 | isa = PBXNativeTarget;
123 | buildConfigurationList = 327E5B231AE753E40086FAF0 /* Build configuration list for PBXNativeTarget "RatingBar" */;
124 | buildPhases = (
125 | 327E5B001AE753E40086FAF0 /* Sources */,
126 | 327E5B011AE753E40086FAF0 /* Frameworks */,
127 | 327E5B021AE753E40086FAF0 /* Resources */,
128 | );
129 | buildRules = (
130 | );
131 | dependencies = (
132 | );
133 | name = RatingBar;
134 | productName = RatingBar;
135 | productReference = 327E5B041AE753E40086FAF0 /* RatingBar.app */;
136 | productType = "com.apple.product-type.application";
137 | };
138 | 327E5B181AE753E40086FAF0 /* RatingBarTests */ = {
139 | isa = PBXNativeTarget;
140 | buildConfigurationList = 327E5B261AE753E40086FAF0 /* Build configuration list for PBXNativeTarget "RatingBarTests" */;
141 | buildPhases = (
142 | 327E5B151AE753E40086FAF0 /* Sources */,
143 | 327E5B161AE753E40086FAF0 /* Frameworks */,
144 | 327E5B171AE753E40086FAF0 /* Resources */,
145 | );
146 | buildRules = (
147 | );
148 | dependencies = (
149 | 327E5B1B1AE753E40086FAF0 /* PBXTargetDependency */,
150 | );
151 | name = RatingBarTests;
152 | productName = RatingBarTests;
153 | productReference = 327E5B191AE753E40086FAF0 /* RatingBarTests.xctest */;
154 | productType = "com.apple.product-type.bundle.unit-test";
155 | };
156 | /* End PBXNativeTarget section */
157 |
158 | /* Begin PBXProject section */
159 | 327E5AFC1AE753E40086FAF0 /* Project object */ = {
160 | isa = PBXProject;
161 | attributes = {
162 | LastUpgradeCheck = 0630;
163 | ORGANIZATIONNAME = Sai;
164 | TargetAttributes = {
165 | 327E5B031AE753E40086FAF0 = {
166 | CreatedOnToolsVersion = 6.3;
167 | };
168 | 327E5B181AE753E40086FAF0 = {
169 | CreatedOnToolsVersion = 6.3;
170 | TestTargetID = 327E5B031AE753E40086FAF0;
171 | };
172 | };
173 | };
174 | buildConfigurationList = 327E5AFF1AE753E40086FAF0 /* Build configuration list for PBXProject "RatingBar" */;
175 | compatibilityVersion = "Xcode 3.2";
176 | developmentRegion = English;
177 | hasScannedForEncodings = 0;
178 | knownRegions = (
179 | en,
180 | Base,
181 | );
182 | mainGroup = 327E5AFB1AE753E40086FAF0;
183 | productRefGroup = 327E5B051AE753E40086FAF0 /* Products */;
184 | projectDirPath = "";
185 | projectRoot = "";
186 | targets = (
187 | 327E5B031AE753E40086FAF0 /* RatingBar */,
188 | 327E5B181AE753E40086FAF0 /* RatingBarTests */,
189 | );
190 | };
191 | /* End PBXProject section */
192 |
193 | /* Begin PBXResourcesBuildPhase section */
194 | 327E5B021AE753E40086FAF0 /* Resources */ = {
195 | isa = PBXResourcesBuildPhase;
196 | buildActionMask = 2147483647;
197 | files = (
198 | 327E5B0F1AE753E40086FAF0 /* Main.storyboard in Resources */,
199 | 327E5B141AE753E40086FAF0 /* LaunchScreen.xib in Resources */,
200 | 327E5B111AE753E40086FAF0 /* Images.xcassets in Resources */,
201 | );
202 | runOnlyForDeploymentPostprocessing = 0;
203 | };
204 | 327E5B171AE753E40086FAF0 /* Resources */ = {
205 | isa = PBXResourcesBuildPhase;
206 | buildActionMask = 2147483647;
207 | files = (
208 | );
209 | runOnlyForDeploymentPostprocessing = 0;
210 | };
211 | /* End PBXResourcesBuildPhase section */
212 |
213 | /* Begin PBXSourcesBuildPhase section */
214 | 327E5B001AE753E40086FAF0 /* Sources */ = {
215 | isa = PBXSourcesBuildPhase;
216 | buildActionMask = 2147483647;
217 | files = (
218 | 327E5B2A1AE773C10086FAF0 /* RatingBar.swift in Sources */,
219 | 327E5B0C1AE753E40086FAF0 /* ViewController.swift in Sources */,
220 | 327E5B0A1AE753E40086FAF0 /* AppDelegate.swift in Sources */,
221 | );
222 | runOnlyForDeploymentPostprocessing = 0;
223 | };
224 | 327E5B151AE753E40086FAF0 /* Sources */ = {
225 | isa = PBXSourcesBuildPhase;
226 | buildActionMask = 2147483647;
227 | files = (
228 | 327E5B201AE753E40086FAF0 /* RatingBarTests.swift in Sources */,
229 | );
230 | runOnlyForDeploymentPostprocessing = 0;
231 | };
232 | /* End PBXSourcesBuildPhase section */
233 |
234 | /* Begin PBXTargetDependency section */
235 | 327E5B1B1AE753E40086FAF0 /* PBXTargetDependency */ = {
236 | isa = PBXTargetDependency;
237 | target = 327E5B031AE753E40086FAF0 /* RatingBar */;
238 | targetProxy = 327E5B1A1AE753E40086FAF0 /* PBXContainerItemProxy */;
239 | };
240 | /* End PBXTargetDependency section */
241 |
242 | /* Begin PBXVariantGroup section */
243 | 327E5B0D1AE753E40086FAF0 /* Main.storyboard */ = {
244 | isa = PBXVariantGroup;
245 | children = (
246 | 327E5B0E1AE753E40086FAF0 /* Base */,
247 | );
248 | name = Main.storyboard;
249 | sourceTree = "";
250 | };
251 | 327E5B121AE753E40086FAF0 /* LaunchScreen.xib */ = {
252 | isa = PBXVariantGroup;
253 | children = (
254 | 327E5B131AE753E40086FAF0 /* Base */,
255 | );
256 | name = LaunchScreen.xib;
257 | sourceTree = "";
258 | };
259 | /* End PBXVariantGroup section */
260 |
261 | /* Begin XCBuildConfiguration section */
262 | 327E5B211AE753E40086FAF0 /* Debug */ = {
263 | isa = XCBuildConfiguration;
264 | buildSettings = {
265 | ALWAYS_SEARCH_USER_PATHS = NO;
266 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
267 | CLANG_CXX_LIBRARY = "libc++";
268 | CLANG_ENABLE_MODULES = YES;
269 | CLANG_ENABLE_OBJC_ARC = YES;
270 | CLANG_WARN_BOOL_CONVERSION = YES;
271 | CLANG_WARN_CONSTANT_CONVERSION = YES;
272 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
273 | CLANG_WARN_EMPTY_BODY = YES;
274 | CLANG_WARN_ENUM_CONVERSION = YES;
275 | CLANG_WARN_INT_CONVERSION = YES;
276 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
277 | CLANG_WARN_UNREACHABLE_CODE = YES;
278 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
279 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
280 | COPY_PHASE_STRIP = NO;
281 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
282 | ENABLE_STRICT_OBJC_MSGSEND = YES;
283 | GCC_C_LANGUAGE_STANDARD = gnu99;
284 | GCC_DYNAMIC_NO_PIC = NO;
285 | GCC_NO_COMMON_BLOCKS = YES;
286 | GCC_OPTIMIZATION_LEVEL = 0;
287 | GCC_PREPROCESSOR_DEFINITIONS = (
288 | "DEBUG=1",
289 | "$(inherited)",
290 | );
291 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
292 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
293 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
294 | GCC_WARN_UNDECLARED_SELECTOR = YES;
295 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
296 | GCC_WARN_UNUSED_FUNCTION = YES;
297 | GCC_WARN_UNUSED_VARIABLE = YES;
298 | IPHONEOS_DEPLOYMENT_TARGET = 8.3;
299 | MTL_ENABLE_DEBUG_INFO = YES;
300 | ONLY_ACTIVE_ARCH = YES;
301 | SDKROOT = iphoneos;
302 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
303 | TARGETED_DEVICE_FAMILY = "1,2";
304 | };
305 | name = Debug;
306 | };
307 | 327E5B221AE753E40086FAF0 /* Release */ = {
308 | isa = XCBuildConfiguration;
309 | buildSettings = {
310 | ALWAYS_SEARCH_USER_PATHS = NO;
311 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
312 | CLANG_CXX_LIBRARY = "libc++";
313 | CLANG_ENABLE_MODULES = YES;
314 | CLANG_ENABLE_OBJC_ARC = YES;
315 | CLANG_WARN_BOOL_CONVERSION = YES;
316 | CLANG_WARN_CONSTANT_CONVERSION = YES;
317 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
318 | CLANG_WARN_EMPTY_BODY = YES;
319 | CLANG_WARN_ENUM_CONVERSION = YES;
320 | CLANG_WARN_INT_CONVERSION = YES;
321 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
322 | CLANG_WARN_UNREACHABLE_CODE = YES;
323 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
324 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
325 | COPY_PHASE_STRIP = NO;
326 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
327 | ENABLE_NS_ASSERTIONS = NO;
328 | ENABLE_STRICT_OBJC_MSGSEND = YES;
329 | GCC_C_LANGUAGE_STANDARD = gnu99;
330 | GCC_NO_COMMON_BLOCKS = YES;
331 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
332 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
333 | GCC_WARN_UNDECLARED_SELECTOR = YES;
334 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
335 | GCC_WARN_UNUSED_FUNCTION = YES;
336 | GCC_WARN_UNUSED_VARIABLE = YES;
337 | IPHONEOS_DEPLOYMENT_TARGET = 8.3;
338 | MTL_ENABLE_DEBUG_INFO = NO;
339 | SDKROOT = iphoneos;
340 | TARGETED_DEVICE_FAMILY = "1,2";
341 | VALIDATE_PRODUCT = YES;
342 | };
343 | name = Release;
344 | };
345 | 327E5B241AE753E40086FAF0 /* Debug */ = {
346 | isa = XCBuildConfiguration;
347 | buildSettings = {
348 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
349 | INFOPLIST_FILE = RatingBar/Info.plist;
350 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
351 | PRODUCT_NAME = "$(TARGET_NAME)";
352 | };
353 | name = Debug;
354 | };
355 | 327E5B251AE753E40086FAF0 /* Release */ = {
356 | isa = XCBuildConfiguration;
357 | buildSettings = {
358 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
359 | INFOPLIST_FILE = RatingBar/Info.plist;
360 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
361 | PRODUCT_NAME = "$(TARGET_NAME)";
362 | };
363 | name = Release;
364 | };
365 | 327E5B271AE753E40086FAF0 /* Debug */ = {
366 | isa = XCBuildConfiguration;
367 | buildSettings = {
368 | BUNDLE_LOADER = "$(TEST_HOST)";
369 | FRAMEWORK_SEARCH_PATHS = (
370 | "$(SDKROOT)/Developer/Library/Frameworks",
371 | "$(inherited)",
372 | );
373 | GCC_PREPROCESSOR_DEFINITIONS = (
374 | "DEBUG=1",
375 | "$(inherited)",
376 | );
377 | INFOPLIST_FILE = RatingBarTests/Info.plist;
378 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
379 | PRODUCT_NAME = "$(TARGET_NAME)";
380 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RatingBar.app/RatingBar";
381 | };
382 | name = Debug;
383 | };
384 | 327E5B281AE753E40086FAF0 /* Release */ = {
385 | isa = XCBuildConfiguration;
386 | buildSettings = {
387 | BUNDLE_LOADER = "$(TEST_HOST)";
388 | FRAMEWORK_SEARCH_PATHS = (
389 | "$(SDKROOT)/Developer/Library/Frameworks",
390 | "$(inherited)",
391 | );
392 | INFOPLIST_FILE = RatingBarTests/Info.plist;
393 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
394 | PRODUCT_NAME = "$(TARGET_NAME)";
395 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RatingBar.app/RatingBar";
396 | };
397 | name = Release;
398 | };
399 | /* End XCBuildConfiguration section */
400 |
401 | /* Begin XCConfigurationList section */
402 | 327E5AFF1AE753E40086FAF0 /* Build configuration list for PBXProject "RatingBar" */ = {
403 | isa = XCConfigurationList;
404 | buildConfigurations = (
405 | 327E5B211AE753E40086FAF0 /* Debug */,
406 | 327E5B221AE753E40086FAF0 /* Release */,
407 | );
408 | defaultConfigurationIsVisible = 0;
409 | defaultConfigurationName = Release;
410 | };
411 | 327E5B231AE753E40086FAF0 /* Build configuration list for PBXNativeTarget "RatingBar" */ = {
412 | isa = XCConfigurationList;
413 | buildConfigurations = (
414 | 327E5B241AE753E40086FAF0 /* Debug */,
415 | 327E5B251AE753E40086FAF0 /* Release */,
416 | );
417 | defaultConfigurationIsVisible = 0;
418 | };
419 | 327E5B261AE753E40086FAF0 /* Build configuration list for PBXNativeTarget "RatingBarTests" */ = {
420 | isa = XCConfigurationList;
421 | buildConfigurations = (
422 | 327E5B271AE753E40086FAF0 /* Debug */,
423 | 327E5B281AE753E40086FAF0 /* Release */,
424 | );
425 | defaultConfigurationIsVisible = 0;
426 | };
427 | /* End XCConfigurationList section */
428 | };
429 | rootObject = 327E5AFC1AE753E40086FAF0 /* Project object */;
430 | }
431 |
--------------------------------------------------------------------------------
/RatingBar.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/RatingBar/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // RatingBar
4 | //
5 | // Created by Sai on 15/4/22.
6 | // Copyright (c) 2015年 Sai. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(application: UIApplication) {
23 | // 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.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(application: UIApplication) {
28 | // 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.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(application: UIApplication) {
37 | // 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.
38 | }
39 |
40 | func applicationWillTerminate(application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/RatingBar/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/RatingBar/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 |
--------------------------------------------------------------------------------
/RatingBar/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/RatingBar/Images.xcassets/ic_ratingbar_star_dark.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "scale" : "2x"
10 | },
11 | {
12 | "idiom" : "universal",
13 | "scale" : "3x",
14 | "filename" : "ic_ratingbar_star_dark@3x.png"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/RatingBar/Images.xcassets/ic_ratingbar_star_dark.imageset/ic_ratingbar_star_dark@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saiwu-bigkoo/iOS-RatingBar/93429bcc73945e377b5c2e16a7d209808cd8fe69/RatingBar/Images.xcassets/ic_ratingbar_star_dark.imageset/ic_ratingbar_star_dark@3x.png
--------------------------------------------------------------------------------
/RatingBar/Images.xcassets/ic_ratingbar_star_light.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x"
6 | },
7 | {
8 | "idiom" : "universal",
9 | "scale" : "2x"
10 | },
11 | {
12 | "idiom" : "universal",
13 | "scale" : "3x",
14 | "filename" : "ic_ratingbar_star_light@3x.png"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/RatingBar/Images.xcassets/ic_ratingbar_star_light.imageset/ic_ratingbar_star_light@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saiwu-bigkoo/iOS-RatingBar/93429bcc73945e377b5c2e16a7d209808cd8fe69/RatingBar/Images.xcassets/ic_ratingbar_star_light.imageset/ic_ratingbar_star_light@3x.png
--------------------------------------------------------------------------------
/RatingBar/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.github.saiwu-bigkoo.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/RatingBar/RatingBar.swift:
--------------------------------------------------------------------------------
1 | // 基本原理:在这个RatingBar里面分别创建两个子View,一个覆盖另一个,每个子View创建numStars个UIImageView,然后通过修改rating的值来控制最顶层的子View可见范围来实现Rating数值变化效果
2 | // RatingBar.swift
3 | // RatingBar
4 | //
5 | // Created by Sai on 15/4/22.
6 | // Copyright (c) 2015年 Sai. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | //@IBDesignable 在视图中拖入控件可以看到渲染情况,结果出现以下错误,http://stackoverflow.com/questions/27374330/ibdesignable-error-ib-designables-failed-to-update-auto-layout-status-interf 这里也是一样情况,暂时无解
11 | //error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed
12 | //error: IB Designables: Failed to render instance of PlaceholderTextView: Rendering the view took longer than 200 ms. Your drawing code may suffer from slow performance.
13 | class RatingBar: UIView {
14 |
15 | @IBInspectable var rating: CGFloat = 0{//当前数值
16 | didSet{
17 | if 0 > rating {rating = 0}
18 | else if ratingMax < rating {rating = ratingMax}
19 | //回调给代理
20 | delegate?.ratingDidChange(self, rating: rating)
21 |
22 | self.setNeedsLayout()
23 | }
24 | }
25 | @IBInspectable var ratingMax: CGFloat = 5//总数值,必须为numStars的倍数
26 | @IBInspectable var numStars: Int = 5 //星星总数
27 | @IBInspectable var canAnimation: Bool = false//是否开启动画模式
28 | @IBInspectable var animationTimeInterval: NSTimeInterval = 0.2//动画时间
29 | @IBInspectable var incomplete:Bool = false//评分时是否允许不是整颗星星
30 | @IBInspectable var isIndicator:Bool = false//RatingBar是否是一个指示器(用户无法进行更改)
31 |
32 | @IBInspectable var imageLight: UIImage = UIImage(named: "ic_ratingbar_star_light")!
33 | @IBInspectable var imageDark: UIImage = UIImage(named: "ic_ratingbar_star_dark")!
34 |
35 | var foregroundRatingView: UIView!
36 | var backgroundRatingView: UIView!
37 |
38 | var delegate: RatingBarDelegate?
39 | var isDrew = false
40 |
41 | func buildView(){
42 | if isDrew {return}
43 | isDrew = true
44 | //创建前后两个View,作用是通过rating数值显示或者隐藏“foregroundRatingView”来改变RatingBar的星星效果
45 | self.backgroundRatingView = self.createRatingView(imageDark)
46 | self.foregroundRatingView = self.createRatingView(imageLight)
47 | animationRatingChange()
48 | self.addSubview(self.backgroundRatingView)
49 | self.addSubview(self.foregroundRatingView)
50 | //加入单击手势
51 | let tapGesture = UITapGestureRecognizer(target: self, action: "tapRateView:")
52 | tapGesture.numberOfTapsRequired = 1
53 | self.addGestureRecognizer(tapGesture)
54 | }
55 | override func layoutSubviews() {
56 | super.layoutSubviews()
57 | buildView()
58 | let animationTimeInterval = self.canAnimation ? self.animationTimeInterval : 0
59 | //开启动画改变foregroundRatingView可见范围
60 | UIView.animateWithDuration(animationTimeInterval, animations: {self.animationRatingChange()})
61 | }
62 | //改变foregroundRatingView可见范围
63 | func animationRatingChange(){
64 | var realRatingScore = self.rating / self.ratingMax
65 | self.foregroundRatingView.frame = CGRectMake(0, 0,self.bounds.size.width * realRatingScore, self.bounds.size.height)
66 |
67 | }
68 | //根据图片名,创建一列RatingView
69 | func createRatingView(image: UIImage) ->UIView{
70 | var view = UIView(frame: self.bounds)
71 | view.clipsToBounds = true
72 | view.backgroundColor = UIColor.clearColor()
73 | //开始创建子Item,根据numStars总数
74 | for position in 0 ..< numStars{
75 | var imageView = UIImageView(image: image)
76 | imageView.frame = CGRectMake(CGFloat(position) * self.bounds.size.width / CGFloat(numStars), 0, self.bounds.size.width / CGFloat(numStars), self.bounds.size.height)
77 | imageView.contentMode = UIViewContentMode.ScaleAspectFit
78 | view.addSubview(imageView)
79 | }
80 | return view
81 | }
82 | //点击编辑分数后,通过手势的x坐标来设置数值
83 | func tapRateView(sender: UITapGestureRecognizer){
84 | if isIndicator {return}//如果是指示器,就不能交互
85 | let tapPoint = sender.locationInView(self)
86 | let offset = tapPoint.x
87 | //通过x坐标判断分数
88 | let realRatingScore = offset / (self.bounds.size.width / ratingMax);
89 | self.rating = self.incomplete ? realRatingScore : round(realRatingScore)
90 |
91 | }
92 | }
93 | protocol RatingBarDelegate{
94 | func ratingDidChange(ratingBar: RatingBar,rating: CGFloat)
95 | }
96 |
--------------------------------------------------------------------------------
/RatingBar/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // RatingBar
4 | //
5 | // Created by Sai on 15/4/22.
6 | // Copyright (c) 2015年 Sai. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController {
12 |
13 | override func viewDidLoad() {
14 | super.viewDidLoad()
15 | // Do any additional setup after loading the view, typically from a nib.
16 | }
17 |
18 | override func didReceiveMemoryWarning() {
19 | super.didReceiveMemoryWarning()
20 | // Dispose of any resources that can be recreated.
21 | }
22 |
23 |
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/RatingBarTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.github.saiwu-bigkoo.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/RatingBarTests/RatingBarTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // RatingBarTests.swift
3 | // RatingBarTests
4 | //
5 | // Created by Sai on 15/4/22.
6 | // Copyright (c) 2015年 Sai. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import XCTest
11 |
12 | class RatingBarTests: XCTestCase {
13 |
14 | override func setUp() {
15 | super.setUp()
16 | // Put setup code here. This method is called before the invocation of each test method in the class.
17 | }
18 |
19 | override func tearDown() {
20 | // Put teardown code here. This method is called after the invocation of each test method in the class.
21 | super.tearDown()
22 | }
23 |
24 | func testExample() {
25 | // This is an example of a functional test case.
26 | XCTAssert(true, "Pass")
27 | }
28 |
29 | func testPerformanceExample() {
30 | // This is an example of a performance test case.
31 | self.measureBlock() {
32 | // Put the code you want to measure the time of here.
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/preview/ratingbardemo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saiwu-bigkoo/iOS-RatingBar/93429bcc73945e377b5c2e16a7d209808cd8fe69/preview/ratingbardemo.gif
--------------------------------------------------------------------------------