[控件] 创建出条形间隔效果的背景LineBackgroundView
2015-03-04 19:28
232 查看
创建出条形间隔效果的背景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:4 lineGap:4 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 <= 0 && self.lineWidth <= 0) { 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(0, 0, containerViewWidth, containerViewWidth)]; self.containerView.layer.borderWidth = 1.f; self.containerView.center = CGPointMake(self.bounds.size.width / 2.f, self.bounds.size.height / 2.f); NSInteger lineViewCount = containerViewWidth / (self.lineGap + self.lineWidth); for (int count = 0; count < lineViewCount + 1; count++) { UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(count * (self.lineGap + self.lineWidth), 0, 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(45)); [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
相关文章推荐
- AutoCompleteTextView控件自定义下拉框背景,点击效果,字体显示效果,匹配条件等效果
- UITableView实现多选时没有效果/控件背景颜色消失了?
- ViewFlipper(多图层控件)及手势识别,代码创建动画效果
- 给iOS SDK中的表格控件(UITableView)添加背景图
- 如何用控件的CALayer 的特性创建 圆角界面,边框,和设置背景
- Flex中如何创建一个自定义数据显示Tips的slider控件。鼠标按住滑标察看效果
- 创建产品列表控件时触发自定义DataUpated事件时,设置MultiView.ActiveViewIndex无效
- 改变LIST控件项被选中的背景提示效果.
- 利用UtilityLibrary.dll WeifenLuo.WinFormsUI.Docking.dll控件创建工具栏效果
- Android TextView控件跑马灯效果
- X3D场景效果节点--Background立体空间背景节点
- Android应用开发——创建一个带动画效果的View
- ASP.NET 动态创建控件引起的ViewState读取问题
- 利用UtilityLibrary.dll WeifenLuo.WinFormsUI.Docking.dll控件创建工具栏效果
- (android控件)巧用background属性,实现图片可选择效果
- GridView控件添加鼠标移入移出时背景行变色的效果
- WPF中创建水晶动画效果的treeview控件
- FLEX教程:改变LIST控件项被选中的背景提示效果.
- Flex中如何通过dropShadowColor, shadowDirection和shadowDistance样式,创建一个有阴影效果的TextArea控件
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)