#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. Python基础篇【第2篇】: Python内置函数(一)

    Python内置函数 lambda lambda表达式相当于函数体为单个return语句的普通函数的匿名函数.请注意,lambda语法并没有使用return关键字.开发者可以在任何可以使用函数引用的位 ...

  2. ServletContextListener使用详解

    在 Servlet API 中有一个 ServletContextListener 接口,它能够监听 ServletContext 对象的生命周期,实际上就是监听 Web 应用的生命周期. 当Serv ...

  3. 创建线程方式-NSThread

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  4. PIC32MZ tutorial -- Timer Interrupt

    An interrupt is an internal or external event that requires quick attention from the controller. The ...

  5. tomcat的乱码问题

    String filename=request.getParameter("filename"); filename=new String(filename.getBytes(&q ...

  6. Spring项目解决Post乱码

    Java EE解决Post乱码:在web.xml中加入: <filter> <filter-name>encodingFilter</filter-name> &l ...

  7. ubuntu mysql emma中文乱码问题解决

    ubuntu mysql emma中文乱码问题解决 emma默认用apt-get 安装的话,emma是不支持中文的,配置文件或直接修改emma程序源文件(python). apt-get安装emma ...

  8. innobackupex的安装

    innobackupex的安装方法有3种: 通过RPM包安装: 通过源码包安装: 通过二进制包安装. 第3种方法最简单,这里只介绍它.以下是安装步骤: 打开官方下载链接: Version默认是最新版本 ...

  9. Java反射得到属性的值和设置属性的值(转)

    package com.whbs.bean; public class UserBean { private Integer id; private int age; private String n ...

  10. sql中列数据横着显示

    列数据横着显示:CREATE TABLE StudenScore(stuname VARCHAR(25) , kc VARCHAR(25) , fs INT)INSERT INTO StudenSco ...