[控件] 创建出条形间隔效果的背景LineBackgroundView
创建出条形间隔效果的背景LineBackgroundView

效果:

使用:
//
// ViewController.m
// LineBackgroundView
//
// Created by XianMingYou on 15/3/4.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "ViewController.h"
#import "LineBackgroundView.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; UIColor *color = [[UIColor blackColor] colorWithAlphaComponent:0.05f];
LineBackgroundView *bgView = [LineBackgroundView createViewWithFrame:self.view.bounds
LineWidth:
lineGap:
lineColor:color];
[self.view addSubview:bgView];
} @end
源码:
//
// LineBackgroundView.h
// LineBackgroundView
//
// Created by XianMingYou on 15/3/4.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import <UIKit/UIKit.h> @interface LineBackgroundView : UIView @property (nonatomic) CGFloat lineWidth;
@property (nonatomic) CGFloat lineGap;
@property (nonatomic, strong) UIColor *lineColor; - (void)buildView;
+ (instancetype)createViewWithFrame:(CGRect)frame
LineWidth:(CGFloat)width
lineGap:(CGFloat)lineGap
lineColor:(UIColor *)color; @end
//
// LineBackgroundView.m
// LineBackgroundView
//
// Created by XianMingYou on 15/3/4.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "LineBackgroundView.h" // 将度数转换为弧度
#define RADIAN(degrees) ((M_PI * (degrees))/ 180.f) @interface LineBackgroundView () @property (nonatomic, strong) UIView *containerView; @end @implementation LineBackgroundView - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.layer.masksToBounds = YES;
}
return self;
} - (void)buildView { if (self.lineGap <= && self.lineWidth <= ) {
return;
} // 获取长度
CGFloat width = self.bounds.size.width;
CGFloat height = self.bounds.size.height;
CGFloat containerViewWidth = (width + height) * 0.75; // 初始化containView
self.containerView = [[UIView alloc] initWithFrame:CGRectMake(, ,
containerViewWidth,
containerViewWidth)];
self.containerView.layer.borderWidth = .f;
self.containerView.center = CGPointMake(self.bounds.size.width / .f,
self.bounds.size.height / .f); NSInteger lineViewCount = containerViewWidth / (self.lineGap + self.lineWidth);
for (int count = ; count < lineViewCount + ; count++) {
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(count * (self.lineGap + self.lineWidth),
,
self.lineWidth,
containerViewWidth)];
if (self.lineColor) {
tempView.backgroundColor = self.lineColor;
} else {
tempView.backgroundColor = [UIColor blackColor];
} [self.containerView addSubview:tempView];
} self.containerView.transform = CGAffineTransformRotate(self.containerView.transform, RADIAN());
[self addSubview:self.containerView];
} + (instancetype)createViewWithFrame:(CGRect)frame
LineWidth:(CGFloat)width
lineGap:(CGFloat)lineGap
lineColor:(UIColor *)color {
LineBackgroundView *bgView = [[LineBackgroundView alloc] initWithFrame:frame];
bgView.lineWidth = width;
bgView.lineGap = lineGap;
bgView.lineColor = color;
[bgView buildView]; return bgView;
} @end

[控件] 创建出条形间隔效果的背景LineBackgroundView的更多相关文章
- 通过WinForm控件创建的WPF控件无法输入的问题
		
今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在我的机器上却是好好的. 最开始以为是输入法的问题,弄了好一阵子 ...
 - SNF开发平台WinForm之三-开发-单表选择控件创建-SNF快速开发平台3.3-Spring.Net.Framework
		
3.1运行效果: 3.2开发实现: 3.2.1 这个开发与第一个开发操作步骤是一致的,不同之处就是在生成完代码之后,留下如下圈红程序,其它删除. 第一个开发地址:开发-单表表格编辑管理页面 http: ...
 - DuiLib(二)——控件创建
		
上一篇讲了窗口及消息,了解了大体的程序框架.这一篇说的是控件的创建. duilib支持XML配置文件,即根据XML创建窗口及控件,将界面与逻辑分开,便于修改及维护.上一篇的示例中可以看到在消息WM_C ...
 - 通过C# WinForm控件创建的WPF WIndow窗口控件无法输入的问题
		
原文:通过WinForm控件创建的WPF 控件无法输入的问题 今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在 ...
 - ToolStrip控件左右拖拽移动效果实现
		
1.主窗体下部添加一个Panel乘放ToolStrip控件以实现ToolStrip在窗体下部定位.2.当ToolStrip控件中子控件超出屏幕时,拖动控件可以实现滑动效果.拖动到控件边缘距窗体边缘1/ ...
 - Xib中设置控件的圆角、边框效果
		
设置控件的圆角和边框效果有两种方式: 1.代码实现: self.myView.layer.masksToBounds = YES; self.myView.layer.cornerRadius = ; ...
 - 根据条件决定My97DatePicker日期控件弹出的日期格式
		
代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
 - iOS之用xib给控件设置圆角、边框效果
		
xib中为各种控件设置圆角 通过代码的方式设置 @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *my ...
 - Android 为控件添加点击涟漪效果
		
Android在5.0版为Button默认添加了点击时的涟漪效果,而且在其他的控件上也可以轻松的实现这种炫酷的效果.涟漪效果可以分为两种,一种时有边界的涟漪,另一种时无边界的涟漪.所谓的有边界,即涟漪 ...
 
随机推荐
- 简单canvas刮刮乐
			
好久没玩canvas了,随便写点效果玩玩.要开始重新拾起这门牛x的技术了,工作中不一定能用得上,以后说不定就能发挥用处了. <!DOCTYPE html> <html lang=&q ...
 - Android Studio 打包生成 APK
			
1. 第一步 Build -> Generate Signed APK 2. 之后会要求开发者输入相关的密钥文件和密码 如果有则找到对应的 .jks 文件输入密码完成相应操作,否则则创建一个对应 ...
 - spring 下载地址及相关概念解析
			
http://www.springsource.org/download/community Release Candidate(RC)候选版本,用于指软件或操作系统的发布,一般与Debug版本相对应 ...
 - SpringBoot相关配置
			
8.1 配置 Spring MVC的配置是通过继承WebMvcConfigurerAdapter类并重载其方法实现的; 前几个教程已做了得配置包括 01点睛Spring MVC 4.1-搭建环境 配置 ...
 - .net WINFORM的GDI双缓冲的实现
			
有时候在窗体中执行不断的GDI+操作的时候会出现闪速的状况,除了修改窗体的参数,更应该解决刷新本身的问题,双缓冲可能就是这样来的. 方法1: 用GDI绘制在位图上,然后再重新生成位图 Bitmap b ...
 - 从数据库表中随机获取N条记录的SQL语句
			
Oracle: select * from (select * from tableName order by dbms_random.value) where rownum < N MS SQ ...
 - 微信小程序学习资料整理
			
基础篇 官网: https://mp.weixin.qq.com/cgi-bin/wx 微信小程序: 小程序是一种新的开放能力,开发者可以快速地开发一个小程序.小程序可以在微信内被便捷地获取和传播,同 ...
 - mysql 中 max_allowed_packet 查询和修改
			
mysql 会根据配置文件限制 server 接收的数据包的大小. 有时候大的插入和更新会被 max_allowed_packet 参数限制,报如下错误: Packet > ). You can ...
 - Nginx面试
			
声明:此文章非本人所 原创,是别人分享所得,如有知道原作者是谁可以联系本人,如有转载请加上此段话 1.请解释一下什么是 Nginx? Nginx是一个 web服务器和反向代理服务器,用于 HTTP.H ...
 - Spring MVC入门(一)—— SpringMVC的执行流程与常用注解
			
一.什么是SpringMVC SpringMVC就是类似于Struts2的mvc框架,属于SpringFrameWork的后续产品.在模型层中与视图层的交互部分. springMVC执行流程: 二.常 ...