-
// Only override drawRect: if you perform custom drawing.
-
// An empty implementation adversely affects performance during animation.
-
- (void)drawRect:(CGRect)rect
-
{
-
CGContextRef context = UIGraphicsGetCurrentContext();
-
-
-
-
/*NO.1画一条线
-
-
CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色
-
CGContextMoveToPoint(context, 20, 20);
-
CGContextAddLineToPoint(context, 200,20);
-
CGContextStrokePath(context);
-
*/
-
-
-
-
/*NO.2写文字
-
-
CGContextSetLineWidth(context, 1.0);
-
CGContextSetRGBFillColor (context, 0.5, 0.5, 0.5, 0.5);
-
UIFont *font = [UIFont boldSystemFontOfSize:18.0];
-
[@"公司:北京中软科技股份有限公司\n部门:ERP事业部\n姓名:McLiang" drawInRect:CGRectMake(20, 40, 280, 300) withFont:font];
-
*/
-
-
-
/*NO.3画一个正方形图形 没有边框
-
-
CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5);
-
CGContextFillRect(context, CGRectMake(2, 2, 270, 270));
-
CGContextStrokePath(context);
-
*/
-
-
-
/*NO.4画正方形边框
-
-
CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色
-
CGContextSetLineWidth(context, 2.0);
-
CGContextAddRect(context, CGRectMake(2, 2, 270, 270));
-
CGContextStrokePath(context);
-
*/
-
-
-
/*NO.5画方形背景颜色
-
-
CGContextTranslateCTM(context, 0.0f, self.bounds.size.height);
-
CGContextScaleCTM(context, 1.0f, -1.0f);
-
UIGraphicsPushContext(context);
-
CGContextSetLineWidth(context,320);
-
CGContextSetRGBStrokeColor(context, 250.0/255, 250.0/255, 210.0/255, 1.0);
-
CGContextStrokeRect(context, CGRectMake(0, 0, 320, 460));
-
UIGraphicsPopContext();
-
*/
-
-
/*NO.6椭圆
-
-
CGRect aRect= CGRectMake(80, 80, 160, 100);
-
CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0);
-
CGContextSetLineWidth(context, 3.0);
-
CGContextAddEllipseInRect(context, aRect); //椭圆
-
CGContextDrawPath(context, kCGPathStroke);
-
*/
-
-
/*NO.7
-
CGContextBeginPath(context);
-
CGContextSetRGBStrokeColor(context, 0, 0, 1, 1);
-
CGContextMoveToPoint(context, 100, 100);
-
CGContextAddArcToPoint(context, 50, 100, 50, 150, 50);
-
CGContextStrokePath(context);
-
*/
-
-
/*NO.8渐变
-
CGContextClip(context);
-
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
-
CGFloat colors[] =
-
{
-
204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00,
-
29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00,
-
0.0 / 255.0, 50.0 / 255.0, 126.0 / 255.0, 1.00,
-
};
-
CGGradientRef gradient = CGGradientCreateWithColorComponents
-
(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));
-
CGColorSpaceRelease(rgb);
-
CGContextDrawLinearGradient(context, gradient,CGPointMake
-
(0.0,0.0) ,CGPointMake(0.0,self.frame.size.height),
-
kCGGradientDrawsBeforeStartLocation);
-
*/
-
-
-
/* NO.9四条线画一个正方形
-
//画线
-
UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0];
-
CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);
-
CGContextSetFillColorWithColor(context, aColor.CGColor);
-
CGContextSetLineWidth(context, 4.0);
-
CGPoint aPoints[5];
-
aPoints[0] =CGPointMake(60, 60);
-
aPoints[1] =CGPointMake(260, 60);
-
aPoints[2] =CGPointMake(260, 300);
-
aPoints[3] =CGPointMake(60, 300);
-
aPoints[4] =CGPointMake(60, 60);
-
CGContextAddLines(context, aPoints, 5);
-
CGContextDrawPath(context, kCGPathStroke); //开始画线
-
*/
-
-
-
-
/* NO.10
-
UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0];
-
CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);
-
CGContextSetFillColorWithColor(context, aColor.CGColor);
-
//椭圆
-
CGRect aRect= CGRectMake(80, 80, 160, 100);
-
CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0);
-
CGContextSetLineWidth(context, 3.0);
-
CGContextSetFillColorWithColor(context, aColor.CGColor);
-
CGContextAddRect(context, rect); //矩形
-
CGContextAddEllipseInRect(context, aRect); //椭圆
-
CGContextDrawPath(context, kCGPathStroke);
-
*/
-
-
-
-
/* NO.11
-
画一个实心的圆
-
-
CGContextFillEllipseInRect(context, CGRectMake(95, 95, 100.0, 100));
-
*/
-
-
-
-
/*NO.12
-
画一个菱形
-
CGContextSetLineWidth(context, 2.0);
-
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
-
CGContextMoveToPoint(context, 100, 100);
-
CGContextAddLineToPoint(context, 150, 150);
-
CGContextAddLineToPoint(context, 100, 200);
-
CGContextAddLineToPoint(context, 50, 150);
-
CGContextAddLineToPoint(context, 100, 100);
-
CGContextStrokePath(context);
-
*/
-
-
/*NO.13 画矩形
-
CGContextSetLineWidth(context, 2.0);
-
-
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
-
-
CGRect rectangle = CGRectMake(60,170,200,80);
-
-
CGContextAddRect(context, rectangle);
-
-
CGContextStrokePath(context);
-
*/
-
-
-
/*椭圆
-
CGContextSetLineWidth(context, 2.0);
-
-
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
-
-
CGRect rectangle = CGRectMake(60,170,200,80);
-
-
CGContextAddEllipseInRect(context, rectangle);
-
-
CGContextStrokePath(context);
-
*/
-
-
/*用红色填充了一段路径:
-
-
CGContextMoveToPoint(context, 100, 100);
-
CGContextAddLineToPoint(context, 150, 150);
-
CGContextAddLineToPoint(context, 100, 200);
-
CGContextAddLineToPoint(context, 50, 150);
-
CGContextAddLineToPoint(context, 100, 100);
-
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
-
CGContextFillPath(context);
-
*/
-
-
/*填充一个蓝色边的红色矩形
-
CGContextSetLineWidth(context, 2.0);
-
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
-
CGRect rectangle = CGRectMake(60,170,200,80);
-
CGContextAddRect(context, rectangle);
-
CGContextStrokePath(context);
-
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
-
CGContextFillRect(context, rectangle);
-
*/
-
-
/*画弧
-
//弧线的是通过指定两个切点,还有角度,调用CGContextAddArcToPoint()绘制
-
CGContextSetLineWidth(context, 2.0);
-
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
-
CGContextMoveToPoint(context, 100, 100);
-
CGContextAddArcToPoint(context, 100,200, 300,200, 100);
-
CGContextStrokePath(context);
-
*/
-
-
-
/*
-
绘制贝兹曲线
-
//贝兹曲线是通过移动一个起始点,然后通过两个控制点,还有一个中止点,调用CGContextAddCurveToPoint() 函数绘制
-
CGContextSetLineWidth(context, 2.0);
-
-
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
-
-
CGContextMoveToPoint(context, 10, 10);
-
-
CGContextAddCurveToPoint(context, 0, 50, 300, 250, 300, 400);
-
-
CGContextStrokePath(context);
-
*/
-
-
/*绘制二次贝兹曲线
-
-
CGContextSetLineWidth(context, 2.0);
-
-
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
-
-
CGContextMoveToPoint(context, 10, 200);
-
-
CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);
-
-
CGContextStrokePath(context);
-
*/
-
-
/*绘制虚线
-
CGContextSetLineWidth(context, 5.0);
-
-
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
-
-
CGFloat dashArray[] = {2,6,4,2};
-
-
CGContextSetLineDash(context, 3, dashArray, 4);//跳过3个再画虚线,所以刚开始有6-(3-2)=5个虚点
-
-
CGContextMoveToPoint(context, 10, 200);
-
-
CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);
-
-
CGContextStrokePath(context);
-
*/
-
/*绘制图片
-
NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
-
UIImage* myImageObj = [[UIImage alloc] initWithContentsOfFile:imagePath];
-
//[myImageObj drawAtPoint:CGPointMake(0, 0)];
-
[myImageObj drawInRect:CGRectMake(0, 0, 320, 480)];
-
-
NSString *s = @"我的小狗";
-
-
[s drawAtPoint:CGPointMake(100, 0) withFont:[UIFont systemFontOfSize:34.0]];
-
*/
-
-
/*
-
NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
-
UIImage *img = [UIImage imageWithContentsOfFile:path];
-
CGImageRef image = img.CGImage;
-
CGContextSaveGState(context);
-
CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
-
CGContextDrawImage(context, touchRect, image);
-
CGContextRestoreGState(context);
-
*/
-
-
-
/*NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
-
UIImage *img = [UIImage imageWithContentsOfFile:path];
-
CGImageRef image = img.CGImage;
-
CGContextSaveGState(context);
-
-
CGContextRotateCTM(context, M_PI);
-
CGContextTranslateCTM(context, -img.size.width, -img.size.height);
-
-
CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
-
CGContextDrawImage(context, touchRect, image);
-
CGContextRestoreGState(context);*/
-
-
/*
-
NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
-
UIImage *img = [UIImage imageWithContentsOfFile:path];
-
CGImageRef image = img.CGImage;
-
-
CGContextSaveGState(context);
-
-
CGAffineTransform myAffine = CGAffineTransformMakeRotation(M_PI);
-
myAffine = CGAffineTransformTranslate(myAffine, -img.size.width, -img.size.height);
-
CGContextConcatCTM(context, myAffine);
-
-
CGContextRotateCTM(context, M_PI);
-
CGContextTranslateCTM(context, -img.size.width, -img.size.height);
-
-
CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
-
CGContextDrawImage(context, touchRect, image);
-
CGContextRestoreGState(context);
-
*/
-
}
相关推荐
FPGA新手必看:XC7Z020最小系统搭建全攻略(附原理图解析)
本文为FPGA新手提供了XC7Z020最小系统搭建的完整实战指南。文章详细解析了电源架构、时钟复位、配置调试等关键硬件电路设计,并重点剖析了外围电路与端口引脚的连接要点及常见陷阱,帮助读者从零开始构建稳定可靠的开发平台。
关于 Drawrect方法的使用
1. 必须在UIView的类里面实现 - (void)drawRect:(CGRect)rect 方法#import "MyView.h"@interface ViewController : UIViewController{ MyView *drawView;}@end @interface MyView : UIView @end #import "MyView.h
基于eBPF和LSM的强制文件访问控制系统架构设计和实现
本文介绍了一种基于 eBPF 与 Linux 安全模块(LSM)实现的强制文件访问控制系统。该系统利用 eBPF 的高性能和动态加载能力以及 LSM 的系统调用拦截功能,提供了灵活且强大的文件访问控制策略。文章详细描述了系统的设计思路、架构组成、关键代码实现及错误处理方式。通过用户空间程序与内核态 eBPF 程序的协作,实现了对文件操作的实时监控和控制,支持动态更新安全策略而无需重启系统。此外,文中还讨论了未来可能的扩展方向,如增加更多 hook 点、集成其他安全模块以及性能优化等。
drawrect 绘制总结
// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { CGContextRe
基于电子海图的水面无人艇全局路径规划
Research and Implementation of Global Path Planning for Unmanned Surface Vehicle Based on Electronic Chart (基于电子海图的水面无人艇全局路径规划) 该论文已经在ICMIR2017会议上发表,附上springer的文献地址 Research and Implementation of Gl...
浅谈一下小波变换和EEG信号处理
浅谈小波变换,总结不是很到位,请大家指正。
重绘机制drawRect
AppDelegate.h文件 #import @interface AppDelegate : UIResponder UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end AppDelegate.m文件 #import "AppDelega
配电网故障重构/孤岛划分/故障恢复
程序主要复现《基于GA_BFGS算法的配电网故障恢复性重构研究_郑海广》,采用matlab编程软件实现,依据网络结构和DG供电方式对配电网进行孤岛划分,将含有 DG 的配电网拓扑结构看成一个树,搭建成连通图模型,使得将孤岛的划分变成了求取最小生成树,以网损和开关开断次数作为目标,采用 IEEE33 节点配电网为算例,通过遗传算法寻优计算,从而得到最佳的重构方案。
Quartz 各种绘制图形用法
// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphi
OpenClaw Docker 安装与部署教程,环境隔离不冲突技术指南
本文介绍了使用Docker容器化部署OpenClaw的完整教程。首先通过流程图详细说明了Docker环境检测流程,包括系统支持性检查、Docker安装状态验证、版本检测和服务配置等步骤。然后提供了Windows、macOS和Linux(Ubuntu/CentOS)系统下的Docker安装指南,涵盖从下载、安装到权限配置的全过程。最后介绍了OpenClaw官方镜像的拉取方法以及自定义镜像构建的Dockerfile示例。该教程适用于开发和生产环境,利用Docker实现环境隔离和快速部署。
YOLOv11改进 | 模型知识蒸馏篇 | 利用模型蒸馏改进YOLOv11进行无损涨点 | 在线蒸馏 (附代码 + 完整文件 + 解析教程)
这篇文章给大家带来的最新改进是模型的蒸馏,利用教师模型指导学生模型从而进行模型的涨点,本文的内容不仅可以用于论文中,在目前的绝大多数的工作中模型蒸馏是一项非常重要的技术,所以大家可以仔细学习一下本文的内容,本文从YOLOv11的项目文件为例,进行详细的修改教程,文章内包括完整的修改教程,针对小白我出了视频修改教程,如果你还不会我提供了修改后的文件大家直接运行即可,所以说不用担心不会适用!模型蒸馏真正的无损涨点,蒸馏你只看这一篇文章就足够了,本文内容为在线蒸馏教程,之前的文章为离线蒸馏!
关于把图片内容绘制到view中
1、把图片内容绘制到view中需要调用的方法 原理:见官方文档// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect {
SAP 合并报表(EC-CS)完整方法论 + 全业务操作步骤
SAP合并报表(EC-CS)方法论与操作指南摘要 SAP EC-CS模块提供完整的集团合并解决方案,其核心方法论基于会计准则和集团管控逻辑,通过6大维度构建标准化合并体系:组织架构标准化、数据采集标准化、外币换算规则化、内部交易自动化抵消、股权与商誉规范化、报表出具灵活化。 实施过程分为两个阶段: 上线前配置阶段(12个步骤):包括合并架构搭建、科目表配置、外币规则设定、抵消规则定义等基础工作 日常操作阶段(10个步骤):涵盖数据报送、外币换算、内部对账、自动抵消、调整分录等月结流程 系统优势包括: 支持多
关于view重绘drawRect
有了view的子类,只要重载一个方法drawRect -(void)drawRect:(CGRect)aRect; 它的参数是个矩形,这个矩形就是你要重绘的区域,你可以忽略参数,它只是为了性能优化,只在固定的区域绘图. 注意!!! 永远不要去调用drawRect,因为drawRect不是让你调用的,而是系统会去调用的. 那怎么去告诉系统需要重绘呢? 你发送两个消息,setNeedsD
OV9734 DATASHEET,完整规格书
OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等
WINCC7.3破解文件
WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!
iOS DrawRect简单使用
今天发现有些人被表格所难住了,我的想法是用 DrawRect进行表格的绘制,那么问题来了,对于 DrawRect我感觉只有大神对其会比较了解,于是我就试着写下关于 DrawRect的简单用法,至于更深的,还需要话时间去研究,今天只带来其最基本的用法,供大家有所了解! 首先我们需要建一个基于 UIView 的类(因为需要在 view 上划线,显示) .h: #import
jre9下载 jdk9
(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】
drawRect方法绘图
iOS的绘图操作是在UIView类的drawRect方法中完成的,所以如果我们要想在一个UIView中绘图,需要写一个扩展UIView 的类,并重写drawRect方法,在这里进行绘图操作,程序会自动调用此方法进行绘图。 下面先说明一下绘图,比如,你想绘制一个方块,你需要写一个类来扩展UIView并在drawRect方法中填入如下代码: - (void)drawRect:(CGRect)rec
SAP B1中文培訓教材_SDK
公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说
android+drawrect边框,drawRect:绘图
drawRect:绘图作用:专门用来绘图 什么时候调用:当View显示的时候调用(ViewWillAppear和ViewDidAppear之间) 参数rect:当View的bounds 在drawRect方法当中系统已经帮你创建一个跟View相关联的上下文(Layer上下文),只要获取上下文就可以了带有边框的图片裁剪步骤:1.假设边框宽度为BorderW2.开启的图片上下文的尺寸就应该是原始图片的...
drawRect与CALayer
setNeedsDisplay会调用(drawRect)方便绘图和setNeedsLayout会调用(layoutSubViews)方便出来数据 UIView的setNeedsDisplay和setNeedsLayout方法。首先两个方法都是异步执行的。setNeedsDisplay会调用自动调用drawRect方法,这样可以拿到UIGraphicsGetCurrentContext,就可以画画了。而setNeedsLayout会默认调用layoutSubViews,就可以处理子视图中的一些数据。 综上两个
Canvas 的drawRect 几个参数理解
昨天写了一个View视图,在上面画了一个矩形,这个视图的最后效果如图: 主要代码如下: package com.view; import com.example.testsql.R; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFa
UIView的DrawRect方法详解
UIView的DrawRect方法,简单说:用来干啥的:就是用来绘图的。如果需要在View中绘制新的一些图形,比如曲线,直线,椭圆等,都需要重写DrawRect方法才可以;什么时候调用:当View显示的时候调用(ViewWillAppear和ViewDidAppear之间)。如果View是隐藏的,也会调用的。转屏会调用,从新设置Frame时会调用;参数rect:当View的bounds 在draw...
UIView drawRect函数
<br />在UIView中画简单图形的一种方法 <br />- (void)drawRect:(CGRect)rect该方法属于UIView的一个方法,想要用该方法画一些基本的图形,需要我们首先子类化UIView,并且重写该类的方法drawRect。下面只是画了一个矩形,并填充相应的颜色。 - (void)drawRect:(CGRect)rect { <br />CGRect newRect = CGRectMake(myRect.origin.x, myRect.origin.y, myRect.s
ios drawRect
Phone重绘机制drawRect 如何使用iPhone进行绘图、重绘操作 iPhone的绘图操作是在UIView类的drawRect方法中完成的,所以如果我们要想在一个UIView中绘图,需要写一个扩展UIView 的类,并重写drawRect方法,在这里进行绘图操作,程序会自动调用此方法进行绘图。 下面先说明一下绘图,比如,你想绘制一个方块,你需要写一个类来扩展UIVie
drawRect绘图
在Java的Swing开发中,常用Graphics2D来绘图,虽然用代码的方式来绘图会比较繁琐,但是貌似有很多攻城狮都乐在其中。 iOS里的Core Graphics框架作为一个绘图框架,也提供了很多手动绘图的常用方法。 UIView的drawRect就像是Java中的paintComponent重绘方法: 1.开始要获取一个指向当前上下文的指针(CGContextRef) - (vo
iOS重绘机制drawRect
iOS的绘图操作是在UIView类的drawRect方法中完成的,所以如果我们要想在一个UIView中绘图,需要写一个扩展UIView 的类,并重写drawRect方法,在这里进行绘图操作,程序会自动调用此方法进行绘图。 下面先说明一下绘图,比如,你想绘制一个方块,你需要写一个类来扩展UIView并在drawRect方法中填入如下代码: - (void)drawRect:(CGRect)r
iOS之DrawRect
DrawRect,iOS重绘视图的方法,我们用的Label、View、button等,他们的形状默认都是矩形的,最多也就是加个圆角,变成椭圆或则圆形而已,但是如果我们想要个五角星形的呢?三角形的呢?举个栗子
iOS快速更新drawRect方法
If you are an advanced user of drawRect on your ipop*, you will know that of course drawRect will not actually run until "all processing is finished." setNeedsDisplay flags a view as invalidated and t
359



被折叠的 条评论
为什么被折叠?



