[控件] 心形加载的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 ...
随机推荐
- Docker笔记:常用命令汇总
Docker常用命令汇总 启动服务 [root@localhost ~]# service docker start Redirecting to /bin/systemctl start docke ...
- sklearn 绘制roc曲线
from sklearn.metrics import roc_curve, auc import matplotlib as mpl import matplotlib.pyplot as plt ...
- [笔记] Python 中JSON数据的读写
前言 JSON(JavaScript Object Notation,JavaScript对象表示法)是一种轻量级的数据交换语言 JSON是独立于语言的文本格式, JSON 数据格式与语言无关 JSO ...
- hadoop的RPC机制 -源码分析
这些天一直奔波于长沙和武汉之间,忙着腾讯的笔试.面试,以至于对hadoop RPC(Remote Procedure Call Protocol ,远程过程调用协议,它是一种通过网络从远程计算机程序上 ...
- vue router的浏览器跳转行为
最近做的项目中,涉及vue router 路由操作,其操作方法不同,产生的行为亦不同.本文通过对比实验,对其行为进行实验对比及总结,避免混淆. vue router的单页跳转的history模式,类似 ...
- Linux下的MongoDB安装&启动&关闭
一.下载安装包 下载地址 二.解压安装包 $ tar -zxvf mongodb-linux-x86_64-3.0.6.tgz 三.复制到指定的目录下 $ mv mongodb-linux-x86_6 ...
- [转]File uploads in ASP.NET Core
本文转自:https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads By Steve Smith ASP.NET MVC ...
- Web前端开发工程师常用技术网站整理
1.常用工具相关 有道云笔记 http://note.youdao.com/signIn/index.html 36镇-最好用的共享收藏夹 http://www.36zhen.com/ 浏览器同步测试 ...
- Java中接口的特点
Java接口在1.8之后发生了重大变化.所以谈Java接口特点可以分为1.8版本之前和1.8版本之后. 1.8版本之前的特点: 接口里只能有静态全局常量和public修饰的抽象方法. 为了代码简洁,在 ...
- Java基础教程(13)--包
为了使类型更易于查找,避免命名冲突和访问控制,我们应该使用包来对自己定义的类型进行管理.这里说的类型可以是类.接口.枚举和注解(枚举和注解的内容会在后续教程中介绍).使用包来管理我们的代码,有以下 ...