在视图内的矩形内绘制简单的线性渐变
我正在阅读有关渐变的文档,但我有点迷失了。 我有一个视图,在该视图内,我只想在一个矩形(小于视图)内从下到上绘制一个简单的黑色到灰色的线性渐变。 我怎样才能做到这一点而不需要子类化任何东西(我读过很多需要子类化视图的东西)?
我正在寻找一种方法来做到这一点,就像我在各种平台上所做的那样简单。类似于(无语言:-)):
blackcolor = MakeBlack();
whiteColor = MakeWhite();
startPoint = MakeStartPoint();
endPoint = MakeEndPoint();
onthisgraphicport = SetGraphicPort(self.view);
clippingRect = MakeClipRect();
DrawGradient(from:whiteColor, to:blackcolor, from:startPoint, to:endPoint, onthisgraphicport, intoThisRect:clippingRect);
谢谢您的帮助。
I'm reading the documentation about gradients and I'm a little bit lost.
I have a view, and inside that view, I just want to draw a simple black to gray linear gradient inside a rect (smaller than the view), from bottom to top.
How may I do that without subclassing anything (I've read many things that need to subclass the view)?
I'm searching a way to do this as simple as I've ever done on various platforms. Something like (language free :-) ) :
blackcolor = MakeBlack();
whiteColor = MakeWhite();
startPoint = MakeStartPoint();
endPoint = MakeEndPoint();
onthisgraphicport = SetGraphicPort(self.view);
clippingRect = MakeClipRect();
DrawGradient(from:whiteColor, to:blackcolor, from:startPoint, to:endPoint, onthisgraphicport, intoThisRect:clippingRect);
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码片段可能会有所帮助。我前段时间在网上找到了这段代码。不幸的是,我忘记了这个网站,所以不知道该归功于谁。
代码按原样绘制白色到黑色的渐变。只需根据您的需要更改矩形和颜色即可。
This code snippet might help. I found the code some time ago on the web. Unfortunately, I forgot the site, so not sure whom to give credit.
The code as is draws a white to black gradient. Just change the rect and the colors to your needs.