[控件] 创建出条形间隔效果的背景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默认添加了点击时的涟漪效果,而且在其他的控件上也可以轻松的实现这种炫酷的效果.涟漪效果可以分为两种,一种时有边界的涟漪,另一种时无边界的涟漪.所谓的有边界,即涟漪 ...
随机推荐
- ubuntu新建用户不能使用ll等指令,显示出来的信息没有颜色区分的解决方案
ubuntu利用 useradd -m test -g admin 指令,创建用户test及其工作目录.但是登陆后,会出现不能使用很多指令“比如:ll.显示的信息没有颜色”等等此时 查看该用户的 ...
- MYSQL根据字段名查询所属表
MYSQL里面需要根据某个字段名,查询该字段名所在的表.这种情况主要是出现在比如你忘了表名,只知道有这样一个字段名,想找出那张表.第二种情况可能是,同一个字段名属于外键,你想找出例如 ID 这个字段 ...
- 1000. A-B
1000. A-B -----> http://soj.me/1000 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Descripti ...
- input属性type为file打开文件资源管理器时,如何限制多次选取或只能一次选取的行为
1.input标签没有设置multiple属性,文件资源管理器默认一次选取 <!doctype html> <html lang="en"> <hea ...
- clientX/Y pageX/Y offsetX/Y layerX/Y screenX/Y clientHeight innerWidth...
关于js鼠标事件综合各大浏览器能获取到坐标的属性总共以下五种 event.clientX/Y event.pageX/Y event.offsetX/Y event.layerX/Y event.sc ...
- WPF 从文件加载字体
本文告诉大家从文件加载字体.在wpf 使用 fontfamily 显示指定的 ttf 显示字体 假如有字体在 C:\Projects\MyProj\free3of9.ttf ,可以使用 Private ...
- [日常] json_encode对中文和引号的处理差异研究
json_encode()1.默认就是把所有 ASCII 可显示字符以外的统统转义为 Unicode如果把那些字符转义为 Unicode 之后,无论文件编码是否一致,都不会出现乱码,因此中文转成Uni ...
- 【原】使用Builder模式替代构造参数传参
前言:关于传递参数,当参数过多的时候我们可以考虑使用建造者模式. #没用 Builder模式 之前是这样传参的: 如下所示,构造方法里面的参数一大堆,看起来就非常的混乱. 用了Builder模式之后是 ...
- Java代理(三)
前面说到了java的动态代理,但是动态代理依赖于接口,这次来看看cglib来实现的代理... 假设有如下方法,这回没有说接口哦~ package proxy.cglibProxy; public cl ...
- WAI-ARIA无障碍网页应用属性完全展示——张鑫旭
一.你至少应该知道ARIA是什么东西! WAI-ARIA指无障碍网页应用.主要针对的是视觉缺陷,失聪,行动不便的残疾人以及假装残疾的测试人员.尤其像盲人,眼睛看不到,其浏览网页则需要借助辅助设备,如屏 ...