- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Apple iOS 编程中 context
概念的新手。目前,我正在考虑 views
。我想用最简单的方法画一个圆弧,然后我找到了这个 question and answer .但是后来我对上下文概念感到困惑。我想画点东西,我需要调用绘图函数并在我希望绘图函数绘制的地方提供 view
。但是在那里,我对 UIGraphicsGetCurrentContext()
感到困惑。那是什么“当前上下文”?是 UIScreen.mainScreen()
吗?如果我想将“当前上下文”设置为 UICollectionViewCell
内的 View ,如何使绘制的所有像素都与 View 相关?我可以这样做吗?
最佳答案
在 CocoaTouch 中绘制的方式是继承 UIView
以创建自定义 View 并实现 drawRect:(CGRect)rect
方法。将绘图代码放在 drawRect
中。像这样的东西:
-(void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGPathRef path = CGPathCreateWithRect(rect, NULL);
[[UIColor blueColor] setStroke];
CGContextSetLineWidth(context, 4.0);
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathFillStroke);
CGPathRelease(path);
}
如果需要,您可以将自定义 UIView 放在 UICollectionViewCell 中。
关于ios - 如何使 CGContextDrawPath 在嵌套 subview 上绘制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39136384/
一位用户报告说我的应用程序正在卡住,他必须强制退出。该应用程序不会崩溃,它只是挂起。他向我发送了文件和条件,但我无法在我的计算机上重现挂起。他向我发送了很长的崩溃日志,但问题似乎发生在 CGConte
我正在尝试制作一个可以描边和填充但不填充的形状。 这是我的代码: - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
我正在尝试填充我绘制的一些三角形,但它们没有填充。下面是在上下文中绘制的代码,正如您在图片中看到的那样,路径描边很好。 func draw(context:CGContextRef) { CG
我在 drawRect 中使用下面的代码 CGContextSaveGState(context); CGMutablePathRef outerPath=[self createPath:rect]
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGCont
我正在尝试绘制一条直线虚线。我已经得到它,所以它绘制了破折号,但这种黑色背景颜色仍然存在。我似乎对其他问题有很多答案,但没有一个有效。 Apple's documentation似乎指向填充颜色并使用
我正在尝试绘制一系列小圆圈,但是当我使用 CGContextDrawPath 时,它会填充我添加到路径中的圆圈之间的线。这是代码: var radius: CGFloat = 3 var bu
我在下面有以下代码,它基本上是 PieChart 的一个切片,其中有许多切片。每个切片都在它自己的 CALayer 中绘制,并使用 addSublayer: 添加到自定义 View 层。 问题是我在用
我是 Apple iOS 编程中 context 概念的新手。目前,我正在考虑 views。我想用最简单的方法画一个圆弧,然后我找到了这个 question and answer .但是后来我对上下文
我正在使用最新的 SDK 开发 iOS 5.0+ 应用。 我是 CoreGraphics 的新手,我不知道如何在 CALayer 上绘制辐射渐变。 我发现我必须使用 CGContextDrawRadi
我收到大量 CGContextDrawPath:无效上下文 0x0。如果您想查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。 此代码中的错误。它在 SKScene 中执
我是一名优秀的程序员,十分优秀!