评分星星New Version
来源:互联网 发布:php调用api接口 post 编辑:程序博客网 时间:2024/05/18 00:32
//// HYBCommentStarView.h// CloudShopping//// Created by huangyibiao on 14-8-4.// Copyright (c) 2014年 uni2uni. All rights reserved.//#import <UIKit/UIKit.h>@class HYBCommentStarView;/*! * @brief 点击星星评分代理 * @author huangyibiao */@protocol HYBCommentStarViewDelegate <NSObject>@optional// 通过调用此方法来获取得分- (void)commentStarView:(HYBCommentStarView *)view score:(float)score;@end/*! * @brief 评论中使用到的星星等级图片显示视图 * @author huangyibiao */@interface HYBCommentStarView : UIView// 获取或设置能否通过点击评分@property (nonatomic, assign) BOOL canTouch;// 总星级数@property (nonatomic, readonly) NSUInteger numberOfStar;@property (nonatomic, weak) id<HYBCommentStarViewDelegate> delegate;- (id)initWithFrame:(CGRect)frame numberOfStar:(int)number;/*! * @brief 设置得分,并更新星级,精确到0.1分 * @param score 评分 */- (void)setScore:(float)score;@end
//// HYBCommentStarView.m// CloudShopping//// Created by huangyibiao on 14-8-4.// Copyright (c) 2014年 uni2uni. All rights reserved.//#import "HYBCommentStarView.h"#define kBackgroundStarImageName @"evaluation_uncheck"#define kForegroundStarImageName @"evaluation_ico"#define kDistance 1.5 // 间隔@interface HYBCommentStarView ()@property (nonatomic, strong) UIView *starBackgroundView;@property (nonatomic, strong) UIView *starForegroundView;@end@implementation HYBCommentStarView- (id)init { return [self initWithFrame:CGRectZero];}- (id)initWithFrame:(CGRect)frame { return [self initWithFrame:frame numberOfStar:5];}- (id)initWithFrame:(CGRect)frame numberOfStar:(int)number { frame.size.width = number * kImageWithName(kBackgroundStarImageName).size.width + number * kDistance; frame.size.height = kImageWithName(kBackgroundStarImageName).size.height; self = [super initWithFrame:frame]; if (self) { self.canTouch = NO; _numberOfStar = number; self.starBackgroundView = [self buidlStarViewWithImageName:kBackgroundStarImageName]; self.starForegroundView = [self buidlStarViewWithImageName:kForegroundStarImageName]; [self addSubview:self.starBackgroundView]; [self addSubview:self.starForegroundView]; [self setScore:0]; } return self;}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (!self.canTouch) { return; } UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; CGRect rect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); if(CGRectContainsPoint(rect,point)) { [self changeStarForegroundViewWithPoint:point]; } return;}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (!self.canTouch) { return; } UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; __weak HYBCommentStarView *weekSelf = self; [UIView transitionWithView:self.starForegroundView duration:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^ { [weekSelf changeStarForegroundViewWithPoint:point]; } completion:nil]; return;}- (UIView *)buidlStarViewWithImageName:(NSString *)imageName { UIView *view = [[UIView alloc] initWithFrame:self.bounds]; view.clipsToBounds = YES; CGFloat originX = 0; for (int i = 0; i < self.numberOfStar; i ++) { CGRect fm = CGRectMake(originX, 0, kImageWithName(kBackgroundStarImageName).size.width, self.height); UIImageView *imageView = [HYBUIMaker imageViewWithFrame:fm imageName:imageName]; originX = imageView.rightX + kDistance; [view addSubview:imageView]; } return view;}- (void)changeStarForegroundViewWithPoint:(CGPoint)point { CGPoint p = point; if (p.x < 0) { p.x = 0; } else if (p.x > self.width) { p.x = self.width; } NSString *str = [NSString stringWithFormat:@"%0.2f", p.x / self.width]; float score = [str floatValue]; p.x = self.width * score + (NSUInteger)score * kDistance; self.starForegroundView.frame = CGRectMake(0, 0, p.x, self.height); if(self.delegate && [self.delegate respondsToSelector:@selector(commentStarView:score:)]) { [self.delegate commentStarView:self score:score]; } return;}- (void)setScore:(float)score { CGPoint point = CGPointZero; point.x = self.width * score + (NSUInteger)score * kDistance; self.starForegroundView.frame = CGRectMake(0, 0, point.x, self.height); if(self.delegate && [self.delegate respondsToSelector:@selector(commentStarView:score:)]) { [self.delegate commentStarView:self score:score]; } return;}@end
0 0
- 评分星星New Version
- 评分星星
- 评分星星
- 星星评分
- 星星评分
- 星星评分
- 星星评分
- iOS 星星评分评分控件
- Jquery星星评分特效
- js实现星星评分
- 评分星星的CSS
- css 手写评分星星
- 星星评分定制
- 网站星星评分效果
- 评分 星星视图
- 星星评分功能
- 封装星星评分视图
- 电影星星评分
- POI导出EXCEL经典实现
- Magento CMS页面添加Contact Us表单 /常用知识
- js 按键事件判断capslock是否开启
- OC特有语法
- Prim算法
- 评分星星New Version
- Spinner常用方法
- QQ5.0 新版 侧滑菜单效果实现!
- 6.3.1 Strategic Game
- dinic
- javascript 鼠标单击和双击事件并存的实现方法
- 谈谈藤艺的消费误区
- SIP 协议在Asterisk中的应用
- sprintf与swprintf