【问题标题】:how to add the shadow, core graphic如何添加阴影,核心图形
【发布时间】:2012-08-15 20:09:44
【问题描述】:

下面是我想在核心图形中绘制的标志。

我要做的是:

Flag.m
- (void)drawRect:(CGRect)rect {

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 1.0);

    CGContextMoveToPoint    (context, 20, 10);
    CGContextAddLineToPoint (context, 50, 10);
    CGContextAddLineToPoint (context, 50, 90);
    CGContextAddLineToPoint (context, 45, 90);
    CGContextAddLineToPoint (context, 45, 95);
    CGContextAddLineToPoint (context, 40, 92);
    CGContextAddLineToPoint (context, 35, 90);
    CGContextAddLineToPoint (context, 30, 92);  
    CGContextAddLineToPoint (context, 25, 95);
    CGContextAddLineToPoint (context, 25, 90); 
    CGContextAddLineToPoint (context, 20, 90);  
    CGContextAddLineToPoint (context, 20, 10);    

    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextFillPath(context);

}

下面是我的结局

我的问题:

如何添加阴影,使我的旗帜看起来像是在尾部折叠和卷曲(就像上面的红旗一样)

【问题讨论】:

    标签: ios core-graphics


    【解决方案1】:

    这是一个相对简化的版本。我注释掉了一些要点,将其分为两部分。首先绘制尾部。然后,主色带在上面绘制。一个漂亮的阴影效果可以用[UIColor colorWithWhite:0.0 alpha:0.4]

    如果您想更漂亮一点,您可以将主要区域的底部几个点绘制为另一个带有渐变的矩形。确保在绘制最后一个矩形之前关闭阴影。

    /*CGContextMoveToPoint    (context, 20, 10);
    CGContextAddLineToPoint (context, 50, 10);*/
    CGContextMoveToPoint    (context, 48, 85);
    CGContextAddLineToPoint (context, 48, 90);
    CGContextAddLineToPoint (context, 45, 90);
    CGContextAddLineToPoint (context, 45, 95);
    CGContextAddLineToPoint (context, 40, 92);
    CGContextAddLineToPoint (context, 35, 90);
    CGContextAddLineToPoint (context, 30, 92);
    CGContextAddLineToPoint (context, 25, 95);
    CGContextAddLineToPoint (context, 25, 90);
    CGContextAddLineToPoint (context, 22, 90);
    CGContextAddLineToPoint (context, 22, 85);
    //CGContextAddLineToPoint (context, 20, 10);
    CGContextSetShadowWithColor(context, CGSizeMake(0, 5.), 3., [UIColor colorWithWhite:0 alpha:.4].CGColor);
    CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:.95 alpha:1].CGColor);
    CGContextFillPath(context);
    CGContextSetShadowWithColor(context, CGSizeMake(0, 2.), 1.5, [UIColor colorWithWhite:0 alpha:.3].CGColor);
    CGContextMoveToPoint    (context, 20, 88);
    CGContextAddLineToPoint (context, 20, 10);
    CGContextAddLineToPoint (context, 50, 10);
    CGContextAddLineToPoint (context, 50, 88);
    CGContextFillPath(context);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多