您的位置:首页 > 大数据 > 人工智能

画图工具PaintCode的使用

2016-06-08 15:05 411 查看
PaintCode 是一个专门为设计师准备的简单的矢量图形绘图应用程序,你可以通过在工具画图自动获取OC代码。
最新的PaintCode2已经可以实现控件的使用(APP
Store中是收费的 还比较贵),只要你能将实现的界面画出来,就可以生成相应的代码,界面的UI布局编码从来都是最浪费时间的东西,PaintCode2可以直接生成代码,当然存在一些不成熟的地方,比如控件之间的相对位置处理,代码仅仅是相对于整个页面的位置(数字表示),这是我觉得比较不成熟的一点,也是很难改进的一点。

虽然有一定缺陷,但是PaintCode
对于画图方面还是有很大用途的,可以通过这个工具描述图形路径,并生成相应的OC或Swift代码。使用很方便,只要在工具中画出想要的图形轮廓就可以获取到相应代码,可以直接拿到项目中使用的。  这只是其中简单的功能,其它功能想要使用还需要自己去开发,因为很多功能是收费的。

下面是画图功能的展示:



代码事例:

@interface
HuaTuViewController
()

@property
(strong,nonatomic)
UIView
*launchView;
@property
(strong,nonatomic)
CAGradientLayer*gradientLayer;
@property
(strong,
nonatomic)
NSTimer
*timer;

@end

@implementation
HuaTuViewController

- (void)viewDidLoad {
    [super
viewDidLoad];
    [self
addLayerToLaunchView];

    // Do any additional setup after loading the view.
}

#pragma mark --
手绘图形显示(CAShapeLayer)(使用
paintCode
工具获取画图代码)
-(void)addLayerToLaunchView
{
   
self.launchView
= [[UIView
alloc]initWithFrame:CGRectMake(0,
0,
100,
100)];

   
self.launchView.center
=
self.view.center;

   
self.launchView.alpha
=
1;

    [self.view
addSubview:self.launchView];

    //self.launchView是我添加的一个显示Logo的UIVIew

    //CAShapeLayer主要是线性,path
里面对颜色的设置无法直接跟随生成,需要单独设置如下:

    /*

     1.
线颜色

     @property CGColorRef strokeColor

    

     2.
填充色

     @property CGColorRef fillColor

    

     3.
填充规则

     @property(copy) NSString *fillRule

     */

   

   
CAShapeLayer *layer = [[CAShapeLayer
alloc]init];

    layer.path
= [self
setBezierPath4].CGPath;

    layer.bounds
=
CGPathGetBoundingBox(layer.path);

    [self.launchView.layer
addSublayer:layer];

   
CAShapeLayer *layer2 = [[CAShapeLayer
alloc]init];

    layer2.path
= [self
setBezierPath2].CGPath;
    layer2.bounds
= CGPathGetBoundingBox(layer.path);

    layer2.fillColor
= [UIColor
greenColor].CGColor;
    [self.launchView.layer
addSublayer:layer2]; 
   

}

-(UIBezierPath*)setBezierPath4

{

    //// PaintCode Trial Version

    ////
www.paintcodeapp.com

   

    //// General Declarations

   
CGColorSpaceRef colorSpace =
CGColorSpaceCreateDeviceRGB();

   
CGContextRef context =
UIGraphicsGetCurrentContext();

   

    //// Color Declarations

   
UIColor* color = [UIColor
colorWithRed:
0.756
green:
0.109
blue:
0.109
alpha:
1];

   

    //// Gradient Declarations

   
CGFloat gradientLocations[] = {0,
1};

   
CGGradientRef gradient =
CGGradientCreateWithColors(colorSpace, (__bridge
CFArrayRef)@[(id)UIColor.greenColor.CGColor,
(id)UIColor.whiteColor.CGColor],
gradientLocations);

   

    //// Bezier Drawing

   
UIBezierPath* bezierPath = [UIBezierPath
bezierPath];

    [bezierPath
moveToPoint:
CGPointMake(214.5,
150.5)];

    [bezierPath
addCurveToPoint:
CGPointMake(193.5,
189.5)
controlPoint1:
CGPointMake(242.5,
150.5)
controlPoint2:
CGPointMake(175.5,
168.5)];

    [bezierPath
addCurveToPoint:
CGPointMake(235.5,
196.5)
controlPoint1:
CGPointMake(211.5,
210.5)
controlPoint2:
CGPointMake(267.5,
185.5)];

    [bezierPath
addCurveToPoint:
CGPointMake(172.5,
207.5)
controlPoint1:
CGPointMake(203.5,
207.5)
controlPoint2:
CGPointMake(206.5,
218.5)];

    [bezierPath
addCurveToPoint:
CGPointMake(103.5,
222.5)
controlPoint1:
CGPointMake(144.18,
198.34)
controlPoint2:
CGPointMake(97.84,
229.67)];

    [bezierPath
addCurveToPoint:
CGPointMake(122.5,
189.5)
controlPoint1:
CGPointMake(104.64,
221.06)
controlPoint2:
CGPointMake(119.49,
192.84)];

    [bezierPath
addCurveToPoint:
CGPointMake(214.5,
150.5)
controlPoint1:
CGPointMake(140.5,
169.5)
controlPoint2:
CGPointMake(186.5,
150.5)];

    [bezierPath
closePath];

   
CGContextSaveGState(context);

    [bezierPath
addClip];

   
CGContextDrawLinearGradient(context, gradient,
CGPointMake(174.11,
150.5),
CGPointMake(174.11,
223.58),
0);

   
CGContextRestoreGState(context);

    [color
setStroke];

    bezierPath.lineWidth
=
1;

    [bezierPath
stroke];
   
   
//// Cleanup
   
CGGradientRelease(gradient);

   
CGColorSpaceRelease(colorSpace);

   
return bezierPath;
}
-(UIBezierPath*)setBezierPath2

{

    //// Color Declarations

   
UIColor* color2 = [UIColor
colorWithRed:
1
green:
0.769
blue:
0 alpha:
1];

    //// Star 2 Drawing

   
UIBezierPath* star2Path = [UIBezierPath
bezierPath];

    [star2Path
moveToPoint:
CGPointMake(88,
58)];

    [star2Path
addLineToPoint:
CGPointMake(89.76,
61.09)];

    [star2Path
addLineToPoint:
CGPointMake(92.76,
62.15)];

    [star2Path
addLineToPoint:
CGPointMake(90.85,
65.11)];

    [star2Path
addLineToPoint:
CGPointMake(90.94,
68.85)];

    [star2Path
addLineToPoint:
CGPointMake(88,
67.6)];

    [star2Path
addLineToPoint:
CGPointMake(85.06,
68.85)];

    [star2Path
addLineToPoint:
CGPointMake(85.15,
65.11)];

    [star2Path
addLineToPoint:
CGPointMake(83.24,
62.15)];

    [star2Path
addLineToPoint:
CGPointMake(86.24,
61.09)];

    [star2Path
closePath];

    [color2
setFill];

    [star2Path
fill];

   
return star2Path;
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息