#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. LINUX下WIFI默认连接

    #! /bin/sh ifconfig wlan0 upiwconfig wlan0 key 123456iwconfig wlan0 essid "rat-linux"iwcon ...

  2. 【练习】flushback基于时间的闪回查询

    1.创建table t1 :: SCOTT@ORA11GR2>create table t1 as select * from scott.emp; Table created. :: SCOT ...

  3. [电脑常见问题] win8 ie浏览器打不开

    我安装的是win8专业版,正版的已经激活了,突然IE浏览器就打不开了,在桌面里面点IE没反应,在Metro界面点IE就回到开始界面 解决办法: 1.Win+R呼出运行窗口,键入Regedit,回车,打 ...

  4. C# XSD校验XML文件的代码

    /// <summary> /// XSD文件校验XML /// </summary> /// <returns></returns> public A ...

  5. HDU 3775 Chain Code ——(Pick定理)

    Pick定理运用在整点围城的面积,有以下公式:S围 = S内(线内部的整点个数)+ S线(线上整点的个数)/2 - 1.在这题上,我们可以用叉乘计算S围,题意要求的答案应该是S内+S线.那么我们进行推 ...

  6. matlab squeeze函数的用法

    matlab中squeeze函数用于删除矩阵中的单一维(Remove singleton dimensions),比如执行下面的代码,随机产生一个1x2x3的矩阵A,然后squeeze(A)将返回一个 ...

  7. [转]LIBSVM-3.18在python环境下的使用

    http://blog.csdn.net/lj695242104/article/details/39500039 1)安装Python,直接去官方网站 2)运行“cmd”,直接输入python,查看 ...

  8. RESULT:0x80029C4A (TYPE_E_CANTLOADLIBRARY))

    无法将类型为"Microsoft.Office.Interop.Excel.ApplicationClass"的 COM 对象强制转换为接口类型"Microsoft.Of ...

  9. Visio控件关闭“形状”面板

    Visio.Window winShapeSearch = axDrawingControl1.Window.Windows.get_ItemFromID((int)Visio.VisWinTypes ...

  10. CommonUtils

    package com.utils; import java.lang.reflect.Field; import java.math.BigDecimal; import java.sql.Time ...