画分割线
2015-07-05 00:30
288 查看
// // ViewController.m // 背景平铺 // // Created by zjj on 15/7/4. // Copyright (c) 2015年 zjj. All rights reserved. // #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UITextView *textViewsLine; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self testViewLine]; // [self testBgLine]; // [self testsBg]; } /** * 给指定控件设置分割线 */ - (void)testViewLine { CGFloat rowW = self.view.frame.size.width; CGFloat rowH = 30;//self.textViewsLine.font.lineHeight; // 创建一行背景图片 UIGraphicsBeginImageContextWithOptions(CGSizeMake(rowW, rowH), NO, 0.0); // 取出上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); // 画个矩形框 [[UIColor whiteColor] set]; CGContextAddRect(ctx, CGRectMake(0, 0, rowW, rowH)); CGContextFillPath(ctx); // 画线 [[UIColor blueColor] set]; CGFloat dividerX = 10;// 分割线与屏幕两边的间距 CGFloat lineWidth = 2; CGContextSetLineWidth(ctx, lineWidth);//设定线宽 CGFloat dividerY = rowH - lineWidth;// Y值为背景图高度减去线宽度 CGContextMoveToPoint(ctx, dividerX, dividerY); CGContextAddLineToPoint(ctx, rowW - dividerX, dividerY); CGContextStrokePath(ctx); // 取图 UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext(); // 结束上下文 UIGraphicsEndImageContext(); self.textViewsLine.backgroundColor = [UIColor colorWithPatternImage:newImg]; } /** * 画 类似通讯录分割线 */ - (void)testBgLine { CGFloat rowW = self.view.frame.size.width; CGFloat rowH = 44; // 创建一行背景图片 UIGraphicsBeginImageContextWithOptions(CGSizeMake(rowW, rowH), NO, 0.0); // 取出上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); // 画个矩形框 [[UIColor whiteColor] set]; CGContextAddRect(ctx, CGRectMake(0, 0, rowW, rowH)); CGContextFillPath(ctx); // 画线 [[UIColor blueColor] set]; CGFloat dividerX = 10;// 分割线与屏幕两边的间距 CGFloat lineWidth = 2; CGContextSetLineWidth(ctx, lineWidth);//设定线宽 CGFloat dividerY = rowH - lineWidth;// Y值为背景图高度减去线宽度 CGContextMoveToPoint(ctx, dividerX, dividerY); CGContextAddLineToPoint(ctx, rowW - dividerX, dividerY); CGContextStrokePath(ctx); // 取图 UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext(); // 结束上下文 UIGraphicsEndImageContext(); self.view.backgroundColor = [UIColor colorWithPatternImage:newImg]; }
/** * 将任意一张图 在不修改尺寸情况下 拉伸平铺到屏幕上 */ - (void)testsBg { UIImage *oldImg = [UIImage imageNamed:@"金币啊"]; UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0); [oldImg drawInRect:self.view.bounds]; UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.view.backgroundColor = [UIColor colorWithPatternImage:newImg]; } @end
相关文章推荐
- Java RMI 入门指南
- javascript 单例模式
- Direct3D-空间物体旋转demo
- C# 面向对象系列笔记(三)
- javascript原型链继承
- Qt 处理XML 文档的三种方式简介——DOM、SAX、流处理
- 静态代码块,构造代码块,构造函数的执行顺序
- PHP命名空间(Namespace)
- 习题3.3---只通过调整指针来达到相邻结点交换的过程
- (2)Zabbix对客户端监控+报警
- 共享经济的近未来
- 习题3.2
- Java RMI之HelloWorld篇
- 认知盈余与共享经济
- 黑马程序员——Java基础--IO流(一)
- NYOJ 蛇形填数在于循环的合理巧妙
- IOS--实现滤镜效果的四种方式
- yarn-resource.java阅读笔记
- IOS--实现滤镜效果的四种方式
- Ubuntu下利用MyEclipse开发Hadoop