#import "RatingView.h"

#define kRatingScale 10

@implementation RatingView

{

UIView *_grayStarView,*_yellowStarView;

}

// 代码创建

- (id)initWithFrame:(CGRect)frame {

if (self = [super initWithFrame:frame]) {

self.backgroundColor = [UIColor clearColor];

[self creatKits];//加载子控件

}

return self;

}

//通过xib文件加载

- (void)awakeFromNib {

[super awakeFromNib];

self.backgroundColor = [UIColor clearColor];

[self creatKits];

}

// 通过storyBoard创建

- (id)initWithCoder:(NSCoder *)aDecoder {

if (self = [super initWithCoder:aDecoder]) {

self.backgroundColor = [UIColor clearColor];

[self creatKits];

}

return self;

}

// 加载子视图

- (void)creatKits {

// 获取加载的星星图片,需要的时图片的饿size属性

UIImage *starImage = [UIImage imageNamed:@"gray"];

CGFloat width = starImage.size.width;

CGFloat height = starImage.size.height;

// 初始化星星视图  宽为星星图片的宽的5倍

_grayStarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,  width*5, height)];

_grayStarView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"gray"]];

[self addSubview:_grayStarView];

_yellowStarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,  width*5, height)];

_yellowStarView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yellow"]];

[self addSubview:_yellowStarView];

// 计算星星视图的形变比例  使得星星视图的大小与评分视图一致

CGFloat scale1 = self.frame.size.width/(width *5);

CGFloat scale2 = self.frame.size.height/height;

_grayStarView.transform = CGAffineTransformMakeScale(scale1, scale2);

_yellowStarView.transform = CGAffineTransformMakeScale(scale1, scale2);

// 重置星星视图的坐标

CGRect grayStarFrame = _grayStarView.frame;

grayStarFrame.origin = CGPointMake(0, 0);

_grayStarView.frame = grayStarFrame;

_yellowStarView.frame = grayStarFrame;

}

- (void)setRating:(CGFloat)rating {

_rating = rating;

CGRect rect = self.bounds;

rect.size.width  = rect.size.width*(rating/kRatingScale);

_yellowStarView.frame = rect;

}

评分视图的封装 (星星 RatingView)的更多相关文章

  1. Django drf:视图层封装、ViewSetMixin、路由配置、解析器、响应器

    一.视图层封装 二.ViewSetMixin 三.路由配置 四.解析器 五.响应器 一.视图层封装 1.基本视图 写一个出版社的增删改查resfull接口 路由: url(r'^publish/$', ...

  2. oracle视图就是封装了一条写好的sql语句 可通过视图修改表结构 ; oracle需要手动创建序列

    create sequence student_sid; --创建序列 oracle只能通过手动方式创建序列

  3. Android星星评分控件RatingBar的使用

    在Android的开发中,有一个叫做评分控件RatingBar,我们可以使用该控件做等级划分.评分等作用,星星形状显示,也可以半星级别,我们来看一下评分控件如何使用. 布局文件中定义控件以及属性,这里 ...

  4. 星星的模块封装类 IDSStarsScoreView

    1 IDSStarsScoreView 的实现效果     2 类的封装方法:   <声明文件>   // //  IDSStarsScoreView.h //  Near // //  ...

  5. restfull规范、DRF视图和路由

    一.restfull规范的简单介绍 1.介绍 REST:表述性状态转移,是一种web交互方案 资源:在web中只要有被引用的必要都是资源 URI: URI 统一资源标识符 URL 统一资源定位符 统一 ...

  6. DRF的视图

    DRF的视图 APIView 我们django中写CBV的时候继承的是View,rest_framework继承的是APIView,那么他们两个有什么不同呢~~~ urlpatterns = [    ...

  7. DRF 视图组件,路由组件

    视图组件  -- 第一次封装   -- GenericAPIView(APIView):    queryset = None    serializer_class = None    def ge ...

  8. cocos-lua基础学习(四)quick层封装后的目录结构

    命名空间 cc cocos2d核心类 ccb cocosbuilder扩展 ccs cocostudio扩展 cocos2d目录结构 bitExtend.lua cocos2d.lua cocos2d ...

  9. 6:django 通用视图

    上一节我们介绍了django视图函数里面几个常用的函数,这节我们来看一下django为我们提供的一些通用视图吧 在最后面有我自己的示例代码,html部分太多了就不贴了 “简单”视图函数 正如名字所言, ...

随机推荐

  1. (LinkedList)Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  2. 在IIS8添加WCF服务支持

    最近在做Silverlight,Windows Phone应用移植到Windows 8平台,在IIS8中测试一些传统WCF服务应用,发现IIS8不支持WCF服务svc请求,后来发现IIS8缺少对WCF ...

  3. MVC 项目中为什么会有两个web.config

    我们对MVC 并不陌生, 在创建MVC项目时,总会发现,在工程目录 中有两个 web.config 文件,一个是在工程的根目录下,一是在 views 下,两个web.config 中的内容也不尽相同, ...

  4. 【EF学习笔记08】----------加载关联表的数据 显式加载

    显式加载 讲解之前,先来看一下我们的数据库结构:班级表 学生表 加载从表集合类型 //显示加载 Console.WriteLine("=========查询集合===========&quo ...

  5. 优雅的设计单线程范围内的数据共享(ThreadLocal)

    单线程范围内数据共享使用ThreadLocal /** * @Description TODO * @author zhanghw@chinatelecom.cn * @since 2015年12月1 ...

  6. PHP 位移运算符(<<左移和>>右移)

    位移运算符 << 位左移 左移运算的实质是将对应的数据的二进制值逐位左移若干位,并在空出的位置上填0,最高位溢出并舍弃.例 如 $a=10; $b=$a<<2; 则$b=40, ...

  7. 线程池的使用ExecutorService

    private ExecutorService executorService = Executors.newFixedThreadPool(5); // 引入线程池来管理多线程 private vo ...

  8. UVa 10071 - Back to High School Physics

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...

  9. handler 异步执行(进度条加载到100)

    生明一个handler 对象(可重写handlerMessage 方法) 声明一个Runnable 对象,需重写run方法 按钮事件:handler对象实例的post方法调用线程. 线程的run方法开 ...

  10. machine learning----->什么是机器学习

    1.概述: 学习一门学问的第一步就是要了解这门学问到底是什么,它可以被用来干什么. 本文罗列了学习machine learning的过程中看到的一些写得比较好的文章以及读完这些文章之后对机器学习的初步 ...