[控件] 心形加载的view
心形加载的view
效果:
素材图片:
源码:
StarView.h 与 StarView.m
- //
- // StarView.h
- // Star
- //
- // Created by XianMingYou on 15/3/13.
- // Copyright (c) 2015年 XianMingYou. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- @interface StarView : UIView
- @property (nonatomic, strong) UIColor *backgroundViewColor;
- @property (nonatomic, strong) UIColor *animationViewColor;
- @property (nonatomic, assign) NSTimeInterval animationDuration;
- + (instancetype)createWithFrame:(CGRect)frame
- backgroundViewColor:(UIColor *)bgColor
- animationViewColor:(UIColor *)anColor;
- - (void)percent:(CGFloat)percent animated:(BOOL)animated;
- @end
- //
- // StarView.m
- // Star
- //
- // Created by XianMingYou on 15/3/13.
- // Copyright (c) 2015年 XianMingYou. All rights reserved.
- //
- #import "StarView.h"
- #import "UIView+SetRect.h"
- @interface StarView ()
- @property (nonatomic, strong) UIImageView *imageView; // 图片
- @property (nonatomic, strong) UIView *backgroundView; // 背景色View
- @property (nonatomic, strong) UIView *animationView; // 做动画的View
- @property (nonatomic) CGFloat height;
- @property (nonatomic) CGFloat width;
- @end
- @implementation StarView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.layer.masksToBounds = YES;
- self.height = frame.size.height;
- self.width = frame.size.width;
- [self addSubview:self.backgroundView];
- [self addSubview:self.animationView];
- [self initImageView];
- }
- return self;
- }
- - (void)initImageView {
- self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
- self.imageView.image = [UIImage imageNamed:@"star"];
- [self addSubview:self.imageView];
- }
- - (void)percent:(CGFloat)percent animated:(BOOL)animated {
- // 过滤percent
- if (percent <= ) {
- percent = ;
- } else if (percent >= ) {
- percent = ;
- }
- if (animated == NO) {
- CGFloat positionY = self.height * ( - percent);
- _animationView.y = positionY;
- } else {
- CGFloat positionY = self.height * ( - percent);
- [UIView animateWithDuration:(self.animationDuration <= ? 0.5 : self.animationDuration)
- animations:^{
- _animationView.y = positionY;
- }];
- }
- }
- + (instancetype)createWithFrame:(CGRect)frame
- backgroundViewColor:(UIColor *)bgColor
- animationViewColor:(UIColor *)anColor {
- StarView *star = [[StarView alloc] initWithFrame:frame];
- star.backgroundViewColor = bgColor;
- star.animationViewColor = anColor;
- return star;
- }
- @synthesize backgroundView = _backgroundView;
- - (UIView *)backgroundView {
- if (_backgroundView == nil) {
- _backgroundView = [[UIView alloc] initWithFrame:self.bounds];
- }
- return _backgroundView;
- }
- @synthesize animationView = _animationView;
- - (UIView *)animationView {
- if (_animationView == nil) {
- _animationView = [[UIView alloc] initWithFrame:CGRectMake(, self.height, self.width, self.height)];
- }
- return _animationView;
- }
- @synthesize backgroundViewColor = _backgroundViewColor;
- - (UIColor *)backgroundViewColor {
- return _backgroundViewColor;
- }
- - (void)setBackgroundViewColor:(UIColor *)backgroundViewColor {
- _backgroundViewColor = backgroundViewColor;
- _backgroundView.backgroundColor = backgroundViewColor;
- }
- @synthesize animationViewColor = _animationViewColor;
- - (UIColor *)animationViewColor {
- return _animationViewColor;
- }
- - (void)setAnimationViewColor:(UIColor *)animationViewColor {
- _animationViewColor = animationViewColor;
- _animationView.backgroundColor = animationViewColor;
- }
- @end
辅助文件 UIView+SetRect.h 与 UIView+SetRect.m
- //
- // UIView+SetRect.h
- // TestPch
- //
- // Created by YouXianMing on 14-12-26.
- // Copyright (c) 2014年 YouXianMing. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- @interface UIView (SetRect)
- // Frame
- @property (nonatomic) CGPoint viewOrigin;
- @property (nonatomic) CGSize viewSize;
- // Frame Origin
- @property (nonatomic) CGFloat x;
- @property (nonatomic) CGFloat y;
- // Frame Size
- @property (nonatomic) CGFloat width;
- @property (nonatomic) CGFloat height;
- // Frame Borders
- @property (nonatomic) CGFloat top;
- @property (nonatomic) CGFloat left;
- @property (nonatomic) CGFloat bottom;
- @property (nonatomic) CGFloat right;
- // Center Point
- #if !IS_IOS_DEVICE
- @property (nonatomic) CGPoint center;
- #endif
- @property (nonatomic) CGFloat centerX;
- @property (nonatomic) CGFloat centerY;
- // Middle Point
- @property (nonatomic, readonly) CGPoint middlePoint;
- @property (nonatomic, readonly) CGFloat middleX;
- @property (nonatomic, readonly) CGFloat middleY;
- @property (nonatomic, assign) CGFloat cornerRadius ;
- @property (nonatomic ,assign) BOOL round ;
- @end
- //
- // UIView+SetRect.m
- // TestPch
- //
- // Created by YouXianMing on 14-12-26.
- // Copyright (c) 2014年 YouXianMing. All rights reserved.
- //
- #import "UIView+SetRect.h"
- @implementation UIView (SetRect)
- #pragma mark Frame
- - (CGPoint)viewOrigin
- {
- return self.frame.origin;
- }
- - (void)setViewOrigin:(CGPoint)newOrigin
- {
- CGRect newFrame = self.frame;
- newFrame.origin = newOrigin;
- self.frame = newFrame;
- }
- - (CGSize)viewSize
- {
- return self.frame.size;
- }
- - (void)setViewSize:(CGSize)newSize
- {
- CGRect newFrame = self.frame;
- newFrame.size = newSize;
- self.frame = newFrame;
- }
- #pragma mark Frame Origin
- - (CGFloat)x
- {
- return self.frame.origin.x;
- }
- - (void)setX:(CGFloat)newX
- {
- CGRect newFrame = self.frame;
- newFrame.origin.x = newX;
- self.frame = newFrame;
- }
- - (CGFloat)y
- {
- return self.frame.origin.y;
- }
- - (void)setY:(CGFloat)newY
- {
- CGRect newFrame = self.frame;
- newFrame.origin.y = newY;
- self.frame = newFrame;
- }
- #pragma mark Frame Size
- - (CGFloat)height
- {
- return self.frame.size.height;
- }
- - (void)setHeight:(CGFloat)newHeight
- {
- CGRect newFrame = self.frame;
- newFrame.size.height = newHeight;
- self.frame = newFrame;
- }
- - (CGFloat)width
- {
- return self.frame.size.width;
- }
- - (void)setWidth:(CGFloat)newWidth
- {
- CGRect newFrame = self.frame;
- newFrame.size.width = newWidth;
- self.frame = newFrame;
- }
- #pragma mark Frame Borders
- - (CGFloat)left
- {
- return self.x;
- }
- - (void)setLeft:(CGFloat)left
- {
- self.x = left;
- }
- - (CGFloat)right
- {
- return self.frame.origin.x + self.frame.size.width;
- }
- - (void)setRight:(CGFloat)right
- {
- self.x = right - self.width;
- }
- - (CGFloat)top
- {
- return self.y;
- }
- - (void)setTop:(CGFloat)top
- {
- self.y = top;
- }
- - (CGFloat)bottom
- {
- return self.frame.origin.y + self.frame.size.height;
- }
- - (void)setBottom:(CGFloat)bottom
- {
- self.y = bottom - self.height;
- }
- #pragma mark Center Point
- #if !IS_IOS_DEVICE
- - (CGPoint)center
- {
- return CGPointMake(self.left + self.middleX, self.top + self.middleY);
- }
- - (void)setCenter:(CGPoint)newCenter
- {
- self.left = newCenter.x - self.middleX;
- self.top = newCenter.y - self.middleY;
- }
- #endif
- - (CGFloat)centerX
- {
- return self.center.x;
- }
- - (void)setCenterX:(CGFloat)newCenterX
- {
- self.center = CGPointMake(newCenterX, self.center.y);
- }
- - (CGFloat)centerY
- {
- return self.center.y;
- }
- - (void)setCenterY:(CGFloat)newCenterY
- {
- self.center = CGPointMake(self.center.x, newCenterY);
- }
- #pragma mark Middle Point
- - (CGPoint)middlePoint
- {
- return CGPointMake(self.middleX, self.middleY);
- }
- - (CGFloat)middleX
- {
- return self.width / ;
- }
- - (CGFloat)middleY
- {
- return self.height / ;
- }
- - (void)setCornerRadius:(CGFloat)cornerRadius
- {
- self.layer.masksToBounds = YES ;
- self.layer.cornerRadius = cornerRadius ;
- }
- - (void)setRound:(BOOL)round
- {
- [self setCornerRadius:self.height/];
- }
- - (CGFloat)cornerRadius
- {
- return self.layer.cornerRadius ;
- }
- - (BOOL)round
- {
- return NO ;
- }
- @end
使用时候的源码:
- //
- // ViewController.m
- // Star
- //
- // Created by XianMingYou on 15/3/13.
- // Copyright (c) 2015年 XianMingYou. All rights reserved.
- //
- #import "ViewController.h"
- #import "StarView.h"
- @interface ViewController ()
- @property (nonatomic, strong) StarView *star;
- @property (nonatomic, strong) NSTimer *timer;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.star = [StarView createWithFrame:CGRectMake(, , , )
- backgroundViewColor:[[UIColor redColor] colorWithAlphaComponent:0.05f]
- animationViewColor:[[UIColor redColor] colorWithAlphaComponent:0.5f]];
- self.star.animationDuration = .f;
- self.star.center = self.view.center;
- [self.view addSubview:self.star];
- self.timer = [NSTimer scheduledTimerWithTimeInterval:1.5f
- target:self
- selector:@selector(timerEvent:)
- userInfo:nil
- repeats:YES];
- }
- - (void)timerEvent:(id)sender {
- CGFloat percent = arc4random() % / .f;
- [self.star percent:percent animated:YES];
- }
- @end
[控件] 心形加载的view的更多相关文章
- jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法
博客分类: jquery-easyui jQueryAjax框架HTML 现象: AJAX返回的html无法做到自动渲染为EasyUI的样式.比如:class="easyui-layout ...
- Winform DevExpress控件库(二) 使用SplashScreenManager控件定制程序加载页面
SplashScreenManager控件:主要作用是显示在进行耗时操作时的等待界面: 位于 工具箱 -> Navigation & Layout(导航栏与布局类控件) 目录下: 在工具 ...
- 使用SplashScreenManager控件定制程序加载页面
需要devexpress版本在12.0及以上才支持 https://www.cnblogs.com/wuhuacong/p/6112461.html 在DevExpress程序中使用SplashScr ...
- zTree 树形控件 ajax动态加载数据
很久没搞过树形控件了 , 再次接触看官网文档有点没懂,于是在网上找了个代码copy上,但数据是写死的,就想这在用ajax异步取出数据替换,下面是js代码 <SCRIPT type="t ...
- 扩展easyUI tab控件,添加加载遮罩效果
项目里要用HighChart显示图表,如果返回的数量量太多,生成图表是一个很耗时的过程.tab控件又没有显示遮罩的设置(至少本菜是没有找到), Google了一下,根据另一个兄台写的方法,拿来改造了一 ...
- Webbrowser控件判断网页加载完毕的简单方法 (转)
摘自:http://blog.csdn.net/cometnet/article/details/5261192 一般情况下,当ReadyState属性变成READYSTATE_COMPLETE时,W ...
- C#自定义控件、用户控件、动态加载菜单按钮
一.效果图,动态加载5个菜单按钮: 二.实现方法 1.创建用户控件 2.在用户控件拖入toolStrip 3.进入用户控件的Lood事件,这里自动添加5个选 ToolStripMenuItem,后期 ...
- asp.net读取用户控件,自定义加载用户控件
1.自定义加载用户控件 ceshi.aspx页面 <html> <body> <div id="divControls" runat="se ...
- 02、获取 WebView 控件中,加载的 HTML 网页内容
在开发 app 的时候,WebView 是经常使用的控件.而且有时需要向 WebView 中的 html 内容 注入额外的 js 进行操作.这里记录一下在当前 WebView 控件中,获取 html ...
随机推荐
- elasticsearch 导入基础数据并索引之 geo_shape
我们看到的图形, 实际是由点来完成的, 有2种类型的格子模型可用于地理星座, 默认使用的是geoHash, 还有一种4叉树(quad trees), 也可用于 判断形状与索引的形状关系 1), int ...
- 【LeetCode题解】206_反转链表(Reverse-Linked-List)
目录 描述 解法一:迭代 思路 Java 实现 Python 实现 复杂度分析 解法二:递归 思路 Java 实现 Python 实现 复杂度分析 更多 LeetCode 题解笔记可以访问我的 git ...
- Spring配置Quartz任务调度、及 ThreadPool 线程池
ONE.除了引入 Spring 相关的 jar 包,还要引入 Quartz 的 jar 包 <dependency> <groupId>org.springframework& ...
- Web 后端--PHP 与数据库的交互
网页要处理数据,数据置于数据库之中.今天看了书,不能让知识遗忘,遂及时记下. 用 PHP 操作 MySQL ,实现数据的交换,还要多练练.... PS: 以下 mysql 字段与mysqli 字段皆 ...
- JS中的编码,解码类型及说明
使用ajax向后台提交的时候 由于参数中含有# 默认会被截断 只保留#之前的字符 json格式的字符串则不会被请求到后台的action 可以使用encodeURIComponent在前台进行编码, ...
- CLR 中 线程的 ThreadState 解释
ThreadState Aborted 线程已停止 AbortedRequested 线程的 Thread.Abort() 方法已被调用,但线程还未停止. Background 线程在后台执行,与 ...
- webfrom后台
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- 【JavaScript 从零开始】 原始值和对象引用、类型转换
JavaScript 中的原始值(undefined.null . 布尔值.数值和字符串)于对象(包括数组和函数)有着根本区别. 原始值是不可更改的:任何方法都无法改变(或“突变”)一个原始值. 对于 ...
- C# 进程优先级和线程优先级的方法
C# 设置进程优先级的方法 this.process1= Process.GetCurrentProcess(); process1.PriorityClass = ProcessPriorityCl ...
- eclipse启动项目报错:java.lang.ClassNotFoundException: ContextLoaderListener
eclipse 启动项目报错:找不到 Spring 监听器类 org.springframework.web.context.ContextLoaderListener 严重: Error confi ...