[英]Change CGRect or Override CGRect
I am drawing a radial gradient in quartz. 我正在绘制石英的径向渐变。 I created a new file and put the code in
drawRect
as 我创建了一个新文件,并将代码放入
drawRect
如下所示:
CGContextRef ctx = UIGraphicsGetCurrentContext();
//Draw the gray Gradient
CGFloat BGLocations[2] = { 0.0, 1.0 };
CGFloat BgComponents[8] = { 0.25, 0.25, 0.25 , 1.0, // Start color
0.11, 0.11, 0.11, 1.0 }; // Mid color and End color
CGColorSpaceRef BgRGBColorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef bgRadialGradient = CGGradientCreateWithColorComponents(BgRGBColorspace, BgComponents, BGLocations, 2);
CGPoint startBg = CGPointMake(250, 250);
CGFloat endRadius= 250;
CGContextDrawRadialGradient(ctx, bgRadialGradient, startBg, 0, startBg, endRadius, kCGGradientDrawsAfterEndLocation);
CGColorSpaceRelease(BgRGBColorspace);
CGGradientRelease(bgRadialGradient);
Now i am making a UIView
and initializing it with the RadialGradientView
created through the website but i need to change the endRadius
according to the different implementations. 现在我想提出一个
UIView
,并与初始化它RadialGradientView
通过创建网站 ,但我需要改变endRadius
根据不同的实现。
IS there a way to do that. 有没有办法做到这一点。
I am initializing the UIView with Frame. 我正在用Frame初始化UIView。
UIView* backgroundView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
UIView* gradientView = [[RadialGradientView alloc] initWithFrame: backgroundView.bounds];
So when i am trying to access endRadius property of gradientView, Its not showing up. 因此,当我尝试访问gradientView的endRadius属性时,它没有显示出来。
Declare the endRadius
as a property in your subclassed yourView.h file as 在您的子类yourView.h文件中,将
endRadius
声明为一个属性,如下所示:
@property(assign) CGFloat endRadius;
and you can access this property like: 您可以像这样访问此属性:
yourView.endRadius=40;
and in the code , change this line: 并在代码中,更改以下行:
CGContextDrawRadialGradient(ctx, bgRadialGradient, startBg, 0, startBg, endRadius, kCGGradientDrawsAfterEndLocation);
to 至
CGContextDrawRadialGradient(ctx, bgRadialGradient, startBg, 0, startBg, self.endRadius, kCGGradientDrawsAfterEndLocation);
or 要么
CGContextDrawRadialGradient(ctx, bgRadialGradient, startBg, 0, startBg, _endRadius, kCGGradientDrawsAfterEndLocation);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.