ShadowDrawing(阴影画图)~demo

//联系人:石虎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"

@implementationSHShadowDrawingView

- (void)drawRect:(CGRect)rect

{

//获取绘图的CGContextRef

CGContextRefctx =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

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

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

谢谢!!!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容