iOS Core Graphics基础入门(3)
来源:互联网 发布:淘宝固定代码 编辑:程序博客网 时间:2024/05/16 18:42
## 绘制阴影// 创建一块画布CGContextRef context = UIGraphicsGetCurrentContext();// 添加阴影颜色 CGContextSetShadowWithColor(context, CGSizeMake(1.2, 1.2), 0, [UIColor lightGrayColor].CGColor);// 绘制字符串 [@"Hello" drawAtPoint:CGPointMake(20, 100) withAttributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:20]}];
## 绘制图片UIImage* image = [UIImage imageNamed:@"02"];// 第一种方法[image drawAtPoint:CGPointMake(0, 0)];// 第二种方法[image drawInRect:CGRectMake(20.f, 20.0f, 320 / 2.f, 568 / 2.f)];
## 绘制屋顶- (void)drawRect:(CGRect)rect{ [self drawRooftopAtTopPointof:CGPointMake(160.0f, 40.0f) textToDisplay:@"Miter" lineJoin:kCGLineJoinMiter]; [self drawRooftopAtTopPointof:CGPointMake(160.0f, 180.0f) textToDisplay:@"Bevel" lineJoin:kCGLineJoinBevel]; [self drawRooftopAtTopPointof:CGPointMake(160.0f, 320.0f) textToDisplay:@"Round" lineJoin:kCGLineJoinRound];}- (void)drawRooftopAtTopPointof:(CGPoint)paramTopPoint textToDisplay:(NSString * )paramText lineJoin:(CGLineJoin)paramLineJoin{ [[UIColor brownColor] set]; CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGContextSetLineJoin(currentContext,paramLineJoin); CGContextSetLineWidth(currentContext, 20.0f); CGContextMoveToPoint(currentContext, paramTopPoint.x - 140, paramTopPoint.y + 100); CGContextAddLineToPoint(currentContext, paramTopPoint.x, paramTopPoint.y); CGContextAddLineToPoint(currentContext, paramTopPoint.x + 140, paramTopPoint.y + 100); CGContextStrokePath(currentContext); [[UIColor blackColor] set]; [paramText drawAtPoint:CGPointMake(paramTopPoint.x - 40.0f, paramTopPoint.y + 60.0f) withFont:[UIFont boldSystemFontOfSize:30.0f]];}
## 绘制矩形CGContextRef context = UIGraphicsGetCurrentContext();CGMutablePathRef path = CGPathCreateMutable();CGPathAddRect(path, NULL, CGRectMake(0, 0, 200, 300));CGContextAddPath(context, path);[[UIColor colorWithRed:1 green:0 blue:0 alpha:1] setFill];[[UIColor greenColor] setStroke];CGContextSetLineWidth(context, 5.0f);CGContextDrawPath(context, kCGPathFillStroke);CGPathRelease(path);
## 绘制多个矩形CGContextRef context = UIGraphicsGetCurrentContext();CGMutablePathRef path = CGPathCreateMutable();CGRect rectangle1 = CGRectMake(20.0f, 20.0f, 200.0f, 300.0f);CGRect rectangle2 = CGRectMake(40.0f, 100.0f, 90.0f, 300.0f);CGRect rectangles[2] = {rectangle1, rectangle2};CGPathAddRects(path, NULL, (const CGRect *)&rectangles, 2);CGContextAddPath(context, path);[[UIColor colorWithRed:0 green:1 blue:0 alpha:1] setFill];[[UIColor blackColor] setStroke];CGContextDrawPath(context, kCGPathFillStroke);CGPathRelease(path);
## 绘制渐变效果CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();UIColor * startColor = [UIColor blueColor];CGFloat * startColorComponents = (CGFloat *)CGColorGetComponents([startColor CGColor]);UIColor * endColor = [UIColor greenColor];CGFloat * endColorComponents = (CGFloat *)CGColorGetComponents([endColor CGColor]);CGFloat colorComponents[8] = { startColorComponents[0], startColorComponents[1], startColorComponents[2], startColorComponents[3], endColorComponents[0], endColorComponents[1], endColorComponents[2], endColorComponents[3]};CGFloat colorIndices[2] = {0.0f,1.0f};CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, (const CGFloat *)&colorComponents, (const CGFloat *)&colorIndices, 2);CGColorSpaceRelease(colorSpace);CGRect screenBounds = [[UIScreen mainScreen] bounds];CGPoint startPoint, endPoint;startPoint = CGPointMake(0.0f, screenBounds.size.height/2.0f);endPoint = CGPointMake(screenBounds.size.width, startPoint.y);CGContextRef currentContext = UIGraphicsGetCurrentContext();CGContextDrawLinearGradient(currentContext,gradient , startPoint, endPoint, 0);CGGradientRelease(gradient);
0 0
- iOS Core Graphics基础入门(3)
- iOS Core Graphics基础入门(1)
- iOS Core Graphics基础入门(2)
- [ios]Core Graphics入门【转】
- Core Graphics快速入门
- iOS -- Core Graphics
- iOS Core Graphics手写板
- iOS Core Graphics介绍
- Core Graphics基础和实践
- iOS Core Graphics封装虚线
- iOS Core Graphics 和 Core Animation
- 使用Core Graphics 进行iOS绘图
- IOS Core Animation 和 Graphics 学习
- iOS Core Graphics之CGContext详解
- Core Graphics-iOS画各种图形
- iOS绘图系统UIKit与Core Graphics
- iOS 图形处理 Core Graphics Quartz2D 教程
- iOS图形编辑之Core Graphics
- C. Exponential notation
- c和指针 前三章的阅读心得
- Mysql存储引擎
- java 与数据库连接 实现用户的注册和登录
- 管道模式
- iOS Core Graphics基础入门(3)
- 用哪种命名方法连接TimesTen? TNS还是DSN
- 自定义注解
- 关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定
- solr简介与安装单机版
- 删除链表中某个结点,假设你只能访问该结点
- Keras Note
- Service
- Android布局:gravity与layout_gravity的区别