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"
@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:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Arial Rounded MT Bold" size: 45]
, NSFontAttributeName ,
[UIColor magentaColor] , NSForegroundColorAttributeName, nil]];
// 设置使用描边模式绘制文字
CGContextSetTextDrawingMode (ctx, kCGTextStroke);
// 绘制文字
[@"iOS 讲义" drawAtPoint:CGPointMake(10 ,124)
withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Heiti SC" size: 40], NSFontAttributeName ,
[UIColor magentaColor] , NSForegroundColorAttributeName, nil]];
// 使用默认的阴影颜色,阴影向右下角投影,模糊度为20
CGContextSetShadowWithColor(ctx, CGSizeMake(10, 8), 10 , [[UIColor redColor] CGColor]);
CGContextFillRect(ctx, CGRectMake(20 , 200 , 180 , 80));
// 设置线条颜色
CGContextSetRGBStrokeColor (ctx, 1, 0, 1, 1);
CGContextStrokeRect(ctx, CGRectMake(30 , 300 , 180 , 80));
}
@end
=========================
===================================================