繁体   English   中英

iOS:动态更改UIView

[英]iOS : changing UIView Dynamically

我有一个应用程序,每当用户绘制一个徒手绘制的圆圈时,该程序都会分配/初始化到一个绘制CAShapelayer圆圈的圆圈类(uiview),而不是由用户绘制。 现在我希望当用户在超级视图上按下按钮时,绘制的圆的alpha将会改变。 这是相关代码:

blueCircleView =[[ASFBlueCircle alloc]initWithFrame:CGRectMake(startPoint.x-10, startPoint.y-20, 60, 60)];

[self addSubview:blueCircleView];

以及该类的初始化代码:

-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code

    self.backgroundColor=[UIColor clearColor];
     UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 75, 75)];
   blueCircleLayer = [CAShapeLayer layer];
    blueCircleLayer.path = circle.CGPath;
    blueCircleLayer.strokeColor = [UIColor blueColor].CGColor;
    blueCircleLayer.fillColor = [UIColor clearColor].CGColor;
    blueCircleLayer.shadowColor =[UIColor blackColor].CGColor;
    blueCircleLayer.shadowOffset = CGSizeMake(0.0f, 5.0f);
    blueCircleLayer.shadowOpacity = 0.7f;
    blueCircleLayer.lineWidth = 7.0;

    [self.layer addSublayer:blueCircleLayer];

在ASFBlueCircle.h中添加属性@property CAShapeLayer * blueCircleLayer;

在init中,在addsublayer之后编写以下行self.blueCircleLayer = blueCircleLayer;

并且在按下按钮时调用的方法self.blueCircleLayer.color = [UIColor colorWithRed:red green:green blue:blue alpha:alpha] .CGColor;

以及所需的红色,绿色,蓝色,alpha值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM