ShadowDrawing(阴影画图)~demo

来源:互联网 发布:外卖人8.6源码下载 编辑:程序博客网 时间:2024/06/05 19:00

//联系人:石虎  QQ: 1224614774昵称:嗡嘛呢叭咪哄

/**

注意点: 1.看 GIF 效果图.

       2.看连线视图的效果图.

       3.看实现代码(直接复制实现效果).

*/

一、GIF 效果图:



二、连线视图的效果图:

图1:



图2:



三、实现代码:

=========================

===================================================

==========================

控制器1: SHContext.h

//

//  SHShadowDrawingView.m

//  ShadowDrawing(阴影画图)~demo

//

//  Created by 石虎 on 2017/8/15.

//  Copyright © 2017 shihu. All rights reserved.

//


#import "SHShadowDrawingView.h"


@implementation SHShadowDrawingView


- (void)drawRect:(CGRect)rect

{

    // 获取绘图的CGContextRef

    CGContextRef ctx =UIGraphicsGetCurrentContext();

    // 使用默认的阴影颜色,阴影向左上角投影,模糊度为5

    CGContextSetShadow(ctx,CGSizeMake(8, -6),5);

    // 设置填充颜色

    CGContextSetRGBFillColor (ctx,1, 0,1, 1);

    // 设置线条颜色

    CGContextSetRGBStrokeColor (ctx,0, 0,1, 1);

    // 设置使用填充模式绘制文字

    CGContextSetTextDrawingMode (ctx,kCGTextFill);

    // 绘制文字

    [@"石虎"drawAtPoint:CGPointMake(10 ,64)

        withAttributes:[NSDictionarydictionaryWithObjectsAndKeys:

                        [UIFontfontWithName:@"Arial Rounded MT Bold"size: 45]

                        , NSFontAttributeName ,

                        [UIColormagentaColor] , NSForegroundColorAttributeName,nil]];

    // 设置使用描边模式绘制文字

    CGContextSetTextDrawingMode (ctx,kCGTextStroke);

    // 绘制文字

    [@"iOS 讲义"drawAtPoint:CGPointMake(10 ,124)

            withAttributes:[NSDictionarydictionaryWithObjectsAndKeys:

                            [UIFontfontWithName:@"Heiti SC"size: 40],NSFontAttributeName ,

                            [UIColormagentaColor] , NSForegroundColorAttributeName,nil]];

    

    // 使用默认的阴影颜色,阴影向右下角投影,模糊度为20

    CGContextSetShadowWithColor(ctx,CGSizeMake(10,8), 10 , [[UIColorredColor] CGColor]);

    CGContextFillRect(ctx,CGRectMake(20 ,200 , 180 , 80));

    

    // 设置线条颜色

    CGContextSetRGBStrokeColor (ctx,1, 0,1, 1);

    CGContextStrokeRect(ctx,CGRectMake(30 ,300 , 180 , 80));

}


@end


=========================

===================================================



谢谢!!!