[控件] 创建出条形间隔效果的背景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默认添加了点击时的涟漪效果,而且在其他的控件上也可以轻松的实现这种炫酷的效果.涟漪效果可以分为两种,一种时有边界的涟漪,另一种时无边界的涟漪.所谓的有边界,即涟漪 ...
随机推荐
- 使用Windbg找出死锁,解决生产环境中运行的软件不响应请求的问题
前言 本文介绍本人的一次使用Windbg分析dump文件找出死锁的过程,并重点介绍如何确定线程所等待的锁及判断是否出现了死锁. 对于如何安装及设置Windbg请参考:<使用Windbg和SoS扩 ...
- 下拉加载dropload.js
使用下拉加载 使用需要引用的css <link rel="stylesheet" href="../dist/dropload.css"> 使用需要 ...
- linux下在线升级nodejs
因现有项目需要用一个截屏node包,此包必须新版本,所以紧急升级下测试环境nodejs,后续再升级线上,小小试了下node在线升级 方案1,使用npm安装n模块,使用n来升级nodejs 首先要知道n ...
- SQL Server如何存储特殊字符、上标、下标
测试验证特殊符号能否存入数据库中: 其中,像一些普通单位符号比如“ ° ′"﹩ $ ﹠ & £¥ ‰ % ℃ ¤ ¢℉”可以正常录入没有问题,但是万分号“‱”之上就不可以了,录入后显 ...
- SqlServer知识点
在公司天天写Sql写,存储过程,但是公司工具模板把创建的语句都写好了,只负责写里面的逻辑,久而久之,创建语句都不会写了.还有一些知识点都很模糊,平常使用的时候都不清楚,稀里糊涂的就在用.在这里整理一下 ...
- jeecg框架解决跨域问题
controller层方法体中添加如下代码 response.setHeader("Access-Control-Allow-Origin", "*");res ...
- idea创建maven的web工程
然后一路点next 接下去添加tomcat 成功 控制台出现乱码的话 输入:-Dfile.encoding=UTF-8 控制台乱码解决
- 让AutoMapper在你的项目里飞一会儿
先说说DTO DTO是个什么东东? DTO(Data Transfer Object)就是数据传输对象,说白了就是一个对象,只不过里边全是数据而已. 为什么要用DTO? 1.DTO更注重数据,对领域对 ...
- UNIX 系统调用:dup,dup2实现重定向
重定向一般在命令行里就是把原本输出到屏幕的数据转而输出到一个指定的文件当中.如 $ pwd > workdir.txt 此时workdir.txt内就存储了pwd命令的输出,当前所在的工作目录 ...
- python学习之老男孩python全栈第九期_day015知识点总结
# 作用域相关(2)locals() # 返回本地作用域中的所有名字 globals() # 返回全局作用域中的所有名字 # 迭代器/生成器相关(3)range()print('__next__' i ...