1 IDSStarsScoreView 的实现效果
 
 
2 类的封装方法:
 
<声明文件>
 
//
//  IDSStarsScoreView.h
//  Near
//
//  Created by levi.duan on 2017/10/23.
//  Copyright © 2017年 Near. All rights reserved.
//
 
#import <UIKit/UIKit.h>
 
@classIDSStarsScoreView;
 
@protocol IDSStarsScoreViewDelegate<NSObject>
 
/**
 评分视图点击回调
 
 @param starsView 评分视图
 @param score 所选分数
 */
- (void)startsScoreView:(IDSStarsScoreView *)starsView didSelectedScore:(CGFloat)score;
 
@end
 
@interface IDSStarsScoreView : UIView
 
// 星星是否可以点击
@property (nonatomic, assign) BOOL clickTheStar;
 
@property (nonatomic, weak) id<IDSStarsScoreViewDelegate> delegate;
 
/*
 * size :图像size
 * margin :两个星星的间距
 * score :显示的星星数
 */
- (instancetype)initWithStarSize:(CGSize)size margin:(CGFloat)margin score:(CGFloat)starNum;
 
/*
 * starNum :显示的星星数
 */
- (void)startInitWithScore:(CGFloat)starNum;
 
/*
 * 获取当前视图评分
 */
- (CGFloat)getCurrentSocore;
 
@end
 
 
<实现文件>
 
//
//  IDSStarsScoreView.m
//  Near
//
//  Created by levi.duan on 2017/10/23.
//  Copyright © 2017年 Near. All rights reserved.
//
 
#import "IDSStarsScoreView.h"
 
@interfaceIDSStarsScoreView ()
 
@property (nonatomic, strong) NSMutableArray *starImageViewArray;
 
@property (nonatomic, assign) CGFloat stores;
 
@end
 
@implementation IDSStarsScoreView
 
 
- (instancetype)initWithStarSize:(CGSize)size margin:(CGFloat)margin score:(CGFloat)starNum
{
    CGRect frame = CGRectMake(0, 0, size.width*5 + margin*4, size.height);
    _stores = starNum;
    _clickTheStar = NO;
    if (self = [superinitWithFrame:frame]) {
        [selfinitWithViewWithTheSize:size margin:margin];
    }
    returnself;
}
 
 
- (void)initWithViewWithTheSize:(CGSize)starSize margin:(CGFloat)starMargin
{
    _starImageViewArray = [[NSMutableArrayalloc] init];
    UIImageView *imageView;
    CGFloat starNum = _stores;
    for (int i=0; i<5; ++i) {
        if (starNum > 0.5) {
            imageView = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"ic_yiqiwan_star1"]];
        }
        elseif (starNum > 0){
            imageView = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"ic_yiqiwan_star3"]];
        }
        else {
            imageView = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"ic_yiqiwan_star2"]];
        }
        imageView.frame = CGRectMake(self.bounds.origin.x+(i*starSize.width+i*starMargin), 0, starSize.width, starSize.height);
        [selfaddSubview:imageView];
        [_starImageViewArrayaddObject:imageView];
        --starNum;
    }
}
 
- (void)startInitWithScore:(CGFloat)starNum
{
    _stores = starNum;
    UIImageView *imageView;
    for (int i=0; i<5; ++i) {
        imageView = _starImageViewArray[i];
        if (starNum > 0.5) {
            imageView.image = [UIImageimageNamed:@"ic_yiqiwan_star1"];
        }
        elseif (starNum > 0){
            imageView.image = [UIImageimageNamed:@"ic_yiqiwan_star3"];
        }
        else {
            imageView.image = [UIImageimageNamed:@"ic_yiqiwan_star2"];
        }
        --starNum;
    }
}
 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (!_clickTheStar) {
        return;
    }
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self];
    UIImageView *imageView ;
    _stores = 0;
    for(int i=0; i<5; ++i){
        imageView = _starImageViewArray[i];
        if ((touchPoint.x > 0) && (touchPoint.x < self.bounds.size.width) && (touchPoint.y > 0) && (touchPoint.y < self.bounds.size.height)) {
            if (imageView.frame.origin.x <= touchPoint.x) {
                ++_stores;
                imageView.image = [UIImageimageNamed:@"ic_yiqiwan_star1"];
            }
            else{
                imageView.image = [UIImageimageNamed:@"ic_yiqiwan_star2"];
            }
        }
    }
    if ([self.delegaterespondsToSelector:@selector(startsScoreView:didSelectedScore:)]) {
        [self.delegatestartsScoreView:selfdidSelectedScore:_stores];
    }
}
 
- (CGFloat)getCurrentSocore
{
    return_stores;
}
 
@end
 
 
声明方法如下:
 
- (IDSStarsScoreView *)starsView
{
    if (!_starsView) {
        if (IS_IPHONE_5 || IS_IPHONE_4_OR_LESS) {
            _starsView = [[IDSStarsScoreViewalloc] initWithStarSize:CGSizeMake(12,12)  margin:0.5score:4.0];
        }
        else {
            _starsView = [[IDSStarsScoreViewalloc] initWithStarSize:CGSizeMake(13,13)  margin:2score:4.0];
        }
        _starsView.frame = CGRectMake(CGRectGetMinX(self.scoreLabel.frame)-_starsView.frame.size.width-3, 0, _starsView.frame.size.width, _starsView.frame.size.height);
        _starsView.centerY = self.scoreLabel.centerY;
    }
    return_starsView;
}
 
数据联调用法如下:
 
if (!IS_NS_STRING_EMPTY(model.gameInfo.score)) {
    _scoreLabel.text = model.gameInfo.score;
    [_scoreLabel sizeToFit];
    _scoreLabel.frame = CGRectMake(self.bounds.size.width-10-_scoreLabel.contentSize.width,99, _scoreLabel.contentSize.width, _scoreLabel.contentSize.height);
    _scoreLabel.centerY = self.soundImageView.centerY;
    [_starsView startInitWithScore:model.gameInfo.score.floatValue];
}
 
 
 
- OVER

星星的模块封装类 IDSStarsScoreView的更多相关文章

  1. 性别年龄的模块封装类 IDSGenderLeviNamedView

    1 IDSGenderLeviNamedView 的实现效果     2 类的封装方法:   IDSGenderLeviNamedView.h   @interface IDSGenderLeviNa ...

  2. 开源日志系统 log4c 使用心得+总结

    http://blog.csdn.net/sky_qing/article/details/7208645 一.安装: 我看网上好多人介绍log4c安装的时候都说有两个步骤:先下载expat安装包并安 ...

  3. 解析大型.NET ERP系统 设计异常处理模块

    异常处理模块是大型系统必备的一个组件,精心设计的异常处理模块可提高系统的健壮性.下面从我理解的角度,谈谈异常处理的方方面面.我的设计仅仅限定于Windows Forms,供参考. 1 定义异常类型 . ...

  4. c#生成静态html文件,封装类

    由于这段时间比较轻松,于是想到很多的企业网站,新闻网站需要将页面静态化,于是写了个封装类来实现静态文件的生成,思路比较简单,但未完善,网友可根据自己的思路将此类扩展,运用了简单工厂模式(本来刚开始看设 ...

  5. C#开发微信门户及应用(43)--微信各个项目模块的定义和相互关系

    我们在开发微信相关的应用的时候,一般需要完善的基础模块支持,包括微信公众号,微信企业号,以及一些业务模块的支持,一般随着功能的增多,我们需要非常清晰的界定他们的关系.模块的分拆以及合并往往需要考虑的代 ...

  6. StackExchange.Redis 访问封装类

    最近需要在C#中使用Redis,在Redis的官网找到了ServiceStack.Redis,最后在测试的时候发现这是个坑,4.0已上已经收费,后面只好找到3系列的最终版本,最后测试发现还是有BUG或 ...

  7. python几个重要的模块备忘

    一:模块使用方法 二:时间模块time 三:系统接口模块os和sys 四:数据保存的几个模块json,pickle,xml,configparse 五:数据复制移动模块shutil 六:日志模块log ...

  8. Android之手机向导以及设置中心模块的开发

    当我们使用的新的软件的时候,我们首先需要教用户如何使用我们的软件,当用户学习完使用教程,下次再登录的时候,我们应该直接跳到我们的功能界面,下面我来展示一下我学习视频做的效果图:手机防盗这个功能模块就是 ...

  9. 第九章:Javascript类和模块

    (过年了,祝大家新年好!) 第6章详细介绍了javascript对象,每个javascript对象都是一个属性集合,相互之间没有任何联系.在javascript中也可以定义对象的类,让每个对象都共享某 ...

随机推荐

  1. redis集群搭建手册

    搭建集群需要用到安装后的redis单机版的bin目录,所以我们先搭建redis单机版 Redis单机版搭建: 因为需要安装redis源码包,所以我们需要gcc环境支持 : 使用FTP工具将压缩包上传至 ...

  2. 用决策树模型求解回归问题(regression tree)

    How do decision trees for regression work? 决策树模型既可以求解分类问题(对应的就是 classification tree),也即对应的目标值是类别型数据, ...

  3. Method for training dynamic random access memory (DRAM) controller timing delays

    Timing delays in a double data rate (DDR) dynamic random access memory (DRAM) controller (114, 116) ...

  4. 经典书单 —— 语言/算法/机器学习/深度学习/AI/CV/PGM

    0.0 计算机科学 <Lex 与 Yacc> Think Complexity(使用 Python 语言) GitHub - AllenDowney/ThinkComplexity: Co ...

  5. 真的懂了:TCP协议中的三次握手和四次挥手(关闭连接时, 当收到对方的FIN报文时, 仅仅表示对方不在发送数据了, 但是还能接收数据, 己方也未必全部数据都发送对方了。相当于一开始还没接上话不要紧,后来接上话以后得让人把话讲完)

    一.TCP报文格式 下面是TCP报文格式图: (1) 序号, Seq(Sequence number), 占32位,用来标识从TCP源端向目的端发送的字节流,发起方发送数据时对此进行标记. (2) 确 ...

  6. WPF 3D编程介绍

    原文:WPF 3D编程介绍 上一篇文章简单的介绍了WPF编程的相关的内容,也推荐了本书.今天要来讲一下在WPF如何开展3D编程. 使用的xmal 和C#开发的时候:需要使用如下的关键要素: 1:摄像机 ...

  7. Tinyhttpd - 超轻量型Http Server,使用C语言开发,全部代码只有502行(包括注释),附带一个简单的Client(Qt也有很多第三方HTTP类)

    - 2. Tinyhttpd tinyhttpd是一个超轻量型Http Server,使用C语言开发,全部代码只有502行(包括注释),附带一个简单的Client,可以通过阅读这段代码理解一个 Htt ...

  8. WPF 获得DataGridRow和 DataGridCell的方法

    原文:WPF 获得DataGridRow和 DataGridCell的方法 原文地址 简介 在WPF中,DataGrid控件并没有提供访问其DataGridRow或者DataGridCell的方法. ...

  9. OpenExpressApp:精通 WPF UI Virtualization

    原文:OpenExpressApp:精通 WPF UI Virtualization 本篇博客主要说明如何使用 UI Virtualization(以下简称为 UIV) 来提升 OEA 框架中 Tre ...

  10. socket 主机地址相关的函数

    #include <arpa/inet.h> int inet_aton (const char *name, struct in_addr *addr) 将ipv4地址从数字点的形式转化 ...