创建出条形间隔效果的背景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的更多相关文章

  1. 通过WinForm控件创建的WPF控件无法输入的问题

    今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在我的机器上却是好好的. 最开始以为是输入法的问题,弄了好一阵子 ...

  2. SNF开发平台WinForm之三-开发-单表选择控件创建-SNF快速开发平台3.3-Spring.Net.Framework

    3.1运行效果: 3.2开发实现: 3.2.1 这个开发与第一个开发操作步骤是一致的,不同之处就是在生成完代码之后,留下如下圈红程序,其它删除. 第一个开发地址:开发-单表表格编辑管理页面 http: ...

  3. DuiLib(二)——控件创建

    上一篇讲了窗口及消息,了解了大体的程序框架.这一篇说的是控件的创建. duilib支持XML配置文件,即根据XML创建窗口及控件,将界面与逻辑分开,便于修改及维护.上一篇的示例中可以看到在消息WM_C ...

  4. 通过C# WinForm控件创建的WPF WIndow窗口控件无法输入的问题

    原文:通过WinForm控件创建的WPF 控件无法输入的问题 今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在 ...

  5. ToolStrip控件左右拖拽移动效果实现

    1.主窗体下部添加一个Panel乘放ToolStrip控件以实现ToolStrip在窗体下部定位.2.当ToolStrip控件中子控件超出屏幕时,拖动控件可以实现滑动效果.拖动到控件边缘距窗体边缘1/ ...

  6. Xib中设置控件的圆角、边框效果

    设置控件的圆角和边框效果有两种方式: 1.代码实现: self.myView.layer.masksToBounds = YES; self.myView.layer.cornerRadius = ; ...

  7. 根据条件决定My97DatePicker日期控件弹出的日期格式

    代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...

  8. iOS之用xib给控件设置圆角、边框效果

    xib中为各种控件设置圆角 通过代码的方式设置 @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *my ...

  9. Android 为控件添加点击涟漪效果

    Android在5.0版为Button默认添加了点击时的涟漪效果,而且在其他的控件上也可以轻松的实现这种炫酷的效果.涟漪效果可以分为两种,一种时有边界的涟漪,另一种时无边界的涟漪.所谓的有边界,即涟漪 ...

随机推荐

  1. 直接用php.exe命令还执行php程序跟直接在网页上访问php程序的区别

    1.直接使用php.exe命令执行php程序的格式: php test.php 2.因为没有经过apache或iis这种服务器,所以一些基于服务器的变量是不能使用的, 如$_SERVER,$_ENV等 ...

  2. HTTP状态码列表

    经常用的http状态码 1xx消息——请求已被服务器接收,继续处理2xx成功——请求已成功被服务器接收.理解.并接受3xx重定向——需要后续操作才能完成这一请求4xx请求错误——请求含有词法错误或者无 ...

  3. 安装sublime text2 for ubuntu

        Add our Sublime Text 2 Ubuntu PPA using the following commands: sudo add-apt-repository ppa:webu ...

  4. SSL虚拟主机安全方案

    SSL虚拟主机安全方案 随着虚拟主机技术的发展,功能越来越丰富,已经不仅仅只是满足个人网站的需要,越来越多的小型电子商务网站也采用了虚拟主机来建站,如何为这些商户提供经济.方便的SSL解决方案,成为虚 ...

  5. vuex中怎么把‘库’中的状态对象赋值给内部对象(三种方法)

    一.通过computed的计算属性直接赋值 import store from '@/store/store' export default{ name: 'count', data(){ retur ...

  6. TFS Negotiate方式登录的IIS配置

    使用vsts-agent连接到tfs(tfs2017)配置代理客户端,可以通过PAT.Negotiate.Integrated.Alternate四种方式登录.(参考) 默认情况下,采用Negotia ...

  7. Supervisord安装和配置

    http://zhangweide.cn/archive/2013/supervisor-note.html Supervisord supervisord的出现,结束了我这苦恼的问题,它可以帮你守护 ...

  8. Wampserver环境配置

    ☆根目录修改问题 /.修改运行根目录 1.修改apache配置,将服务请求定位到新目录下 →左击wampserver,点击Apache打开httpd.conf文件,Ctrl+f搜索documentro ...

  9. Unity3D 场景切换加载进度条实现

    需要三个场景,场景A,场景B,场景C: 场景A:一个按钮,点击加载场景B: 场景B:从A切换到C过度场景,加载进度条: 场景C:目标场景: 创建OnProgress.cs脚本: using Syste ...

  10. Ubuntu中网络配置interfaces与界面网络配置NetworkManager

    [Server版本] 在Ubuntu Server版本中,因为只存有命令行模式,所以要想进行网络参数设置,只能通过修改 /etc/network/interfaces .具体设置方法如下: (1) U ...