开发者

Horizontal Gradient with a rounded rect path?

开发者 https://www.devze.com 2023-02-06 06:25 出处:网络
I have a custom UIView I\'m drawing using CoreGraphics. Using CoreGraphics, how would I set a horizontal gradient and clip it to my rounded rect path while still using a shadow? I wrote as much as the

I have a custom UIView I'm drawing using CoreGraphics. Using CoreGraphics, how would I set a horizontal gradient and clip it to my rounded rect path while still using a shadow? I wrote as much as the path and I can fill it with a color using setFill, but the gradient (a horizontal one, too) isn't abiding by the path...

EDIT: Since 开发者_开发百科the time of posting (not so long ago), I figured out how to do a complex horizontal gradient, so now my only problem is drawing it within my CGContext's path.


Well it seems I've found my own answer:

CGContextAddPath(context, path);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawLinearGradient(context, gradient, startPt, endPt, 0);

Those lines of code perfectly clip it to the path of a rounded rect, or any path desired.

0

精彩评论

暂无评论...
验证码 换一张
取 消