评分视图的封装 (星星 RatingView)
#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)的更多相关文章
- Django drf:视图层封装、ViewSetMixin、路由配置、解析器、响应器
一.视图层封装 二.ViewSetMixin 三.路由配置 四.解析器 五.响应器 一.视图层封装 1.基本视图 写一个出版社的增删改查resfull接口 路由: url(r'^publish/$', ...
- oracle视图就是封装了一条写好的sql语句 可通过视图修改表结构 ; oracle需要手动创建序列
create sequence student_sid; --创建序列 oracle只能通过手动方式创建序列
- Android星星评分控件RatingBar的使用
在Android的开发中,有一个叫做评分控件RatingBar,我们可以使用该控件做等级划分.评分等作用,星星形状显示,也可以半星级别,我们来看一下评分控件如何使用. 布局文件中定义控件以及属性,这里 ...
- 星星的模块封装类 IDSStarsScoreView
1 IDSStarsScoreView 的实现效果 2 类的封装方法: <声明文件> // // IDSStarsScoreView.h // Near // // ...
- restfull规范、DRF视图和路由
一.restfull规范的简单介绍 1.介绍 REST:表述性状态转移,是一种web交互方案 资源:在web中只要有被引用的必要都是资源 URI: URI 统一资源标识符 URL 统一资源定位符 统一 ...
- DRF的视图
DRF的视图 APIView 我们django中写CBV的时候继承的是View,rest_framework继承的是APIView,那么他们两个有什么不同呢~~~ urlpatterns = [ ...
- DRF 视图组件,路由组件
视图组件 -- 第一次封装 -- GenericAPIView(APIView): queryset = None serializer_class = None def ge ...
- cocos-lua基础学习(四)quick层封装后的目录结构
命名空间 cc cocos2d核心类 ccb cocosbuilder扩展 ccs cocostudio扩展 cocos2d目录结构 bitExtend.lua cocos2d.lua cocos2d ...
- 6:django 通用视图
上一节我们介绍了django视图函数里面几个常用的函数,这节我们来看一下django为我们提供的一些通用视图吧 在最后面有我自己的示例代码,html部分太多了就不贴了 “简单”视图函数 正如名字所言, ...
随机推荐
- poj 2513 Colored Sticks trie树+欧拉图+并查集
点击打开链接 Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27955 Accepted ...
- Unity3D 双摇杆 c# JoyStick 实现自己的双摇杆
转载请声明: http://www.cnblogs.com/ADaii/p/3859520.html Untiy3D 官方摇杆脚本只能完成一个摇杆,要实现双摇杆比较费劲 现在我吧我废了一通宵的结果共享 ...
- cocos2dx3.0 removeFromParent和removeAllChildren含义
顾名思义,removeFromParent就是把自己从父亲那里移除,removeAllChildren就是移除自己所有的孩子,这些方法的具体实现都在基类Node里面,通过查看代码也很容易看到怎么实现的 ...
- C#GridViewExport帮助类,美化导出
1.将整GridView的数据导出到Excel中关增加一个效果线做美化 最新的GridViewExport操作类 using System.Data; using System.Web; using ...
- php 向asmx发送请求 || php 发送xml请求, 以及处理返回的xml结果
var $live_url = 'https://processing.ukash.com/RPPGateway/process.asmx'; $source = array( 'SecurityTo ...
- safari渲染Transition动画不流畅问题
用css3的transition过渡来做页面动画的时候,发现在chrome和ff流畅,在safari 不流畅: 度娘找到了淘宝UED的一个类似解决方案,动画就流畅了. 测试环境: win7 32bit ...
- JAVA的包装类 【转】
Java语言是一个面向对象的语言,但是Java中的基本数据类型却是不面向对象的,这在实际使用时存在很多的不便,为了解决这个不足,在设计类时为每个基本数据类型设计了一个对应的类进行代表,这样八个和基本数 ...
- 2.openssl rsa/pkey
分别是RSA密钥的处理工具和通用非对称密钥处理工具.它们用法基本一致,所以只介绍openssl rsa. [root@xuexi tmp]# man rsa NAME rsa - RSA key pr ...
- Nginx服务测试时的一些配置:wireshark、常用搜索URL格式、关闭防火墙、siege
wrieshark sudo yum install wireshark-gnome sudo wireshar (以root启动,否则看不到网卡) 网站URL格式 以查询lumia为例 google ...
- python学习笔记1-元类__metaclass__
type 其实就是元类,type 是python 背后创建所有对象的元类 python 中的类的创建规则: 假设创建Foo 这个类 class Foo(Bar): def __init__(): ...