[控件] 创建出条形间隔效果的背景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默认添加了点击时的涟漪效果,而且在其他的控件上也可以轻松的实现这种炫酷的效果.涟漪效果可以分为两种,一种时有边界的涟漪,另一种时无边界的涟漪.所谓的有边界,即涟漪 ...
随机推荐
- tomcat启动(六)Catalina分析-StandardServer.start()
从链接 Tomcat中组件的生命周期管理公共接口Lifecycle 可以知道调用的是StandardServer.startInternal() @Override protected void st ...
- tomcat启动(二)org.apache.catalina.startup.Bootstrap分析
/** * Bootstrap loader for Catalina. This application constructs a class loader * for use in loading ...
- C#的进度条透明的情况(穿透问题)
如图: 很明显,可以看到透过进度条的框框可以看到下面的软件界面, 之前出现这种情况是因为pictureBox和panel层级之间的关系造成的, 没想到这次的原因居然不是这样,而是因为少了backCol ...
- C/C++中的常量到底存在了什么地方
一般来说,基本类型(整型.字符型等)常量会在编译阶段被编译成立即数,占的是代码段的内存.(代码段是只读的,而且不允程序员获取代码段的地址,所以在c++中,尽量不为const分配数据段的内存,但是一旦取 ...
- struct in_addr 结构体
struct in_addr 结构体: struct in_addr { in_addr_t s_addr; }; 表示一个32位的IPv4地址. in_addr_t一般为32位的unsigned i ...
- Koa2实用入门
koa2已发布了一段时间,可以考虑入手,参见Node.js最新Web技术栈(2016年4月) 本文主要是koa 2的文档解读和runkoa介绍,让大家对koa 2有一个更简单直接的理解 一.依赖Nod ...
- SpringMVC源码阅读:核心分发器DispatcherServlet
1.前言 SpringMVC是目前J2EE平台的主流Web框架,不熟悉的园友可以看SpringMVC源码阅读入门,它交代了SpringMVC的基础知识和源码阅读的技巧 本文将介绍SpringMVC的核 ...
- bzoj 4912: [Sdoi2017]天才黑客
Description Solution 这个题和点没什么关系 , 之和边与边之间关系有关 , 我们就把边看作点 , 边权就是 \(lcp\) , 点权看作这条边本来的权值. 现在考虑两两连边 , \ ...
- [转]Lost parameter value during SQL trace in EF Core DbParameter 为 问号 ?
本文转自:https://stackoverflow.com/questions/44202478/lost-parameter-value-during-sql-trace-in-ef-core 问 ...
- dev控件ASPxComboBox设置ReadOnly="true"后
dev控件ASPxComboBox设置ReadOnly="true"后,在后台OnCallback事件中赋值前台不显示