GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 提交文件 · DevQC/DevPodTestGo@b7d1acc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Class
    • CWStarRateView.h
    • CWStarRateView.m
  • DevPodTestGo.podspec
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Class/CWStarRateView.h‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// CWStarRateView.h
3+
// StarRateDemo
4+
//
5+
// Created by WANGCHAO on 14/11/4.
6+
// Copyright (c) 2014年 wangchao. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@class CWStarRateView;
12+
@protocol CWStarRateViewDelegate <NSObject>
13+
@optional
14+
- (void)starRateView:(CWStarRateView *)starRateView scroePercentDidChange:(CGFloat)newScorePercent;
15+
@end
16+
17+
@interface CWStarRateView : UIView
18+
19+
@property (nonatomic, assign) CGFloat scorePercent;//得分值,范围为0--1,默认为1
20+
@property (nonatomic, assign) BOOL hasAnimation;//是否允许动画,默认为NO
21+
@property (nonatomic, assign) BOOL allowIncompleteStar;//评分时是否允许不是整星,默认为NO
22+
23+
@property (nonatomic, weak) id<CWStarRateViewDelegate>delegate;
24+
25+
- (instancetype)initWithFrame:(CGRect)frame
26+
numberOfStars:(NSInteger)numberOfStars
27+
selStarImageName:(NSString *)selStarImageName
28+
norStarImageName:(NSString *)norStarImageName;
29+
30+
@end
Collapse file

‎Class/CWStarRateView.m‎

Copy file name to clipboard
+135Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
//
2+
// CWStarRateView.m
3+
// StarRateDemo
4+
//
5+
// Created by WANGCHAO on 14/11/4.
6+
// Copyright (c) 2014年 wangchao. All rights reserved.
7+
//
8+
9+
#import "CWStarRateView.h"
10+
11+
#define FOREGROUND_STAR_IMAGE_NAME @"designer_star_sel_img"
12+
#define BACKGROUND_STAR_IMAGE_NAME @"designer_star_nor_img"
13+
#define DEFALUT_STAR_NUMBER 5
14+
#define ANIMATION_TIME_INTERVAL 0.2
15+
16+
@interface CWStarRateView ()
17+
18+
@property (nonatomic, strong) UIView *foregroundStarView;
19+
@property (nonatomic, strong) UIView *backgroundStarView;
20+
21+
@property (nonatomic, assign) NSInteger numberOfStars;
22+
@property (nonatomic, strong) NSString *foregroundStarImageName;
23+
@property (nonatomic, strong) NSString *backgroundStarImageName;
24+
25+
@end
26+
27+
@implementation CWStarRateView
28+
29+
#pragma mark - Init Methods
30+
- (instancetype)init {
31+
NSAssert(NO, @"You should never call this method in this class. Use initWithFrame: instead!");
32+
return nil;
33+
}
34+
35+
- (instancetype)initWithFrame:(CGRect)frame {
36+
return [self initWithFrame:frame numberOfStars:DEFALUT_STAR_NUMBER selStarImageName:FOREGROUND_STAR_IMAGE_NAME norStarImageName:BACKGROUND_STAR_IMAGE_NAME];
37+
}
38+
39+
- (instancetype)initWithCoder:(NSCoder *)aDecoder
40+
selStarImageName:(NSString *)selStarImageName
41+
norStarImageName:(NSString *)norStarImageName{
42+
if (self = [super initWithCoder:aDecoder]) {
43+
_numberOfStars = DEFALUT_STAR_NUMBER;
44+
_foregroundStarImageName = selStarImageName;
45+
_backgroundStarImageName = norStarImageName;
46+
[self buildDataAndUI];
47+
}
48+
return self;
49+
}
50+
51+
- (instancetype)initWithFrame:(CGRect)frame
52+
numberOfStars:(NSInteger)numberOfStars
53+
selStarImageName:(NSString *)selStarImageName
54+
norStarImageName:(NSString *)norStarImageName{
55+
if (self = [super initWithFrame:frame]) {
56+
_numberOfStars = numberOfStars;
57+
_foregroundStarImageName = selStarImageName;
58+
_backgroundStarImageName = norStarImageName;
59+
[self buildDataAndUI];
60+
}
61+
return self;
62+
}
63+
64+
#pragma mark - Private Methods
65+
66+
- (void)buildDataAndUI{
67+
_scorePercent = 1;//默认为1
68+
_hasAnimation = NO;//默认为NO
69+
_allowIncompleteStar = NO;//默认为NO
70+
71+
self.foregroundStarView = [self createStarViewWithImage:_foregroundStarImageName];
72+
self.backgroundStarView = [self createStarViewWithImage:_backgroundStarImageName];
73+
74+
[self addSubview:self.backgroundStarView];
75+
[self addSubview:self.foregroundStarView];
76+
77+
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userTapRateView:)];
78+
tapGesture.numberOfTapsRequired = 1;
79+
[self addGestureRecognizer:tapGesture];
80+
}
81+
82+
- (void)userTapRateView:(UITapGestureRecognizer *)gesture {
83+
CGPoint tapPoint = [gesture locationInView:self];
84+
CGFloat offset = tapPoint.x;
85+
CGFloat realStarScore = offset / (self.bounds.size.width / self.numberOfStars);
86+
CGFloat starScore = self.allowIncompleteStar ? realStarScore : ceilf(realStarScore);
87+
self.scorePercent = starScore / self.numberOfStars;
88+
}
89+
90+
- (UIView *)createStarViewWithImage:(NSString *)imageName {
91+
UIView *view = [[UIView alloc] initWithFrame:self.bounds];
92+
view.clipsToBounds = YES;
93+
view.backgroundColor = [UIColor clearColor];
94+
for (NSInteger i = 0; i < self.numberOfStars; i ++)
95+
{
96+
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
97+
imageView.frame = CGRectMake(i * self.bounds.size.width / self.numberOfStars, 0, self.bounds.size.width / self.numberOfStars, self.bounds.size.height);
98+
imageView.contentMode = UIViewContentModeScaleAspectFit;
99+
[view addSubview:imageView];
100+
}
101+
return view;
102+
}
103+
104+
- (void)layoutSubviews {
105+
[super layoutSubviews];
106+
__weak CWStarRateView *weakSelf = self;
107+
CGFloat animationTimeInterval = self.hasAnimation ? ANIMATION_TIME_INTERVAL : 0;
108+
[UIView animateWithDuration:animationTimeInterval animations:^{
109+
weakSelf.foregroundStarView.frame = CGRectMake(0, 0, weakSelf.bounds.size.width * weakSelf.scorePercent, weakSelf.bounds.size.height);
110+
}];
111+
}
112+
113+
#pragma mark - Get and Set Methods
114+
115+
- (void)setScorePercent:(CGFloat)scroePercent {
116+
if (_scorePercent == scroePercent) {
117+
return;
118+
}
119+
120+
if (scroePercent < 0) {
121+
_scorePercent = 0;
122+
} else if (scroePercent > 1) {
123+
_scorePercent = 1;
124+
} else {
125+
_scorePercent = scroePercent;
126+
}
127+
128+
if ([self.delegate respondsToSelector:@selector(starRateView:scroePercentDidChange:)]) {
129+
[self.delegate starRateView:self scroePercentDidChange:scroePercent];
130+
}
131+
132+
[self setNeedsLayout];
133+
}
134+
135+
@end
Collapse file

‎DevPodTestGo.podspec‎

Copy file name to clipboard
+138Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#
2+
# Be sure to run `pod spec lint DevPodTestGo.podspec' to ensure this is a
3+
# valid spec and to remove all comments including this before submitting the spec.
4+
#
5+
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6+
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7+
#
8+
9+
Pod::Spec.new do |s|
10+
11+
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12+
#
13+
# These will help people to find your library, and whilst it
14+
# can feel like a chore to fill in it's definitely to your advantage. The
15+
# summary should be tweet-length, and the description more in depth.
16+
#
17+
18+
s.name = "DevPodTestGo"
19+
s.version = "0.0.1"
20+
s.summary = "A short description of DevPodTestGo."
21+
22+
# This description is used to generate tags and improve search results.
23+
# * Think: What does it do? Why did you write it? What is the focus?
24+
# * Try to keep it short, snappy and to the point.
25+
# * Write the description between the DESC delimiters below.
26+
# * Finally, don't worry about the indent, CocoaPods strips it!
27+
s.description = <<-DESC
28+
add some des here
29+
DESC
30+
31+
s.homepage = "https://github.com/DevQC/DevPodTestGo"
32+
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
33+
34+
35+
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
36+
#
37+
# Licensing your code is important. See http://choosealicense.com for more info.
38+
# CocoaPods will detect a license file if there is a named LICENSE*
39+
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
40+
#
41+
42+
s.license = "MIT (example)"
43+
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
44+
45+
46+
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
47+
#
48+
# Specify the authors of the library, with email addresses. Email addresses
49+
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
50+
# accepts just a name if you'd rather not provide an email address.
51+
#
52+
# Specify a social_media_url where others can refer to, for example a twitter
53+
# profile URL.
54+
#
55+
56+
s.author = { "deven.chen" => "[email protected]" }
57+
# Or just: s.author = "deven.chen"
58+
# s.authors = { "deven.chen" => "[email protected]" }
59+
# s.social_media_url = "http://twitter.com/deven.chen"
60+
61+
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
62+
#
63+
# If this Pod runs only on iOS or OS X, then specify the platform and
64+
# the deployment target. You can optionally include the target after the platform.
65+
#
66+
67+
# s.platform = :ios
68+
s.platform = :ios, "7.0"
69+
70+
# When using multiple platforms
71+
# s.ios.deployment_target = "5.0"
72+
# s.osx.deployment_target = "10.7"
73+
# s.watchos.deployment_target = "2.0"
74+
# s.tvos.deployment_target = "9.0"
75+
76+
77+
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
78+
#
79+
# Specify the location from where the source should be retrieved.
80+
# Supports git, hg, bzr, svn and HTTP.
81+
#
82+
83+
s.source = { :git => "https://github.com/DevQC/DevPodTestGo.git", :tag => "#{s.version}" }
84+
85+
86+
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
87+
#
88+
# CocoaPods is smart about how it includes source code. For source files
89+
# giving a folder will include any swift, h, m, mm, c & cpp files.
90+
# For header files it will include any header in the folder.
91+
# Not including the public_header_files will make all headers public.
92+
#
93+
94+
s.source_files = "Classes", "Classes/**/*.{h,m}"
95+
# s.exclude_files = "Classes/Exclude"
96+
97+
# s.public_header_files = "Classes/**/*.h"
98+
99+
100+
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
101+
#
102+
# A list of resources included with the Pod. These are copied into the
103+
# target bundle with a build phase script. Anything else will be cleaned.
104+
# You can preserve files from being cleaned, please don't preserve
105+
# non-essential files like tests, examples and documentation.
106+
#
107+
108+
# s.resource = "icon.png"
109+
# s.resources = "Resources/*.png"
110+
111+
# s.preserve_paths = "FilesToSave", "MoreFilesToSave"
112+
113+
114+
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
115+
#
116+
# Link your library with frameworks, or libraries. Libraries do not include
117+
# the lib prefix of their name.
118+
#
119+
120+
# s.framework = "SomeFramework"
121+
# s.frameworks = "SomeFramework", "AnotherFramework"
122+
123+
# s.library = "iconv"
124+
# s.libraries = "iconv", "xml2"
125+
126+
127+
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
128+
#
129+
# If your library depends on compiler flags you can set them in the xcconfig hash
130+
# where they will only apply to your library. If you depend on other Podspecs
131+
# you can include multiple dependencies to ensure it works.
132+
133+
s.requires_arc = true
134+
135+
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
136+
# s.dependency "JSONKit", "~> 1.4"
137+
138+
end

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.