Created
February 24, 2019 12:08
-
-
Save VAndrJ/4ccf6c395409ece23d37345496f5cd7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ArcView.m | |
// UIBezierPathExampleForLI | |
// | |
// Created by Volodymyr Andriienko on 2/23/19. | |
// Copyright © 2019 VAndrJ. All rights reserved. | |
// | |
#import "ArcView.h" | |
@implementation ArcView | |
- (void)drawRect:(CGRect)rect { | |
[[UIColor blackColor] setStroke]; | |
let path = [UIBezierPath new]; | |
let lineWidth = rect.size.height / 30; | |
let centerPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); | |
let arcRadius = MIN(rect.size.height / 2, rect.size.width / 2) - lineWidth / 2; | |
[path setLineWidth:lineWidth]; | |
[path addArcWithCenter:centerPoint radius:arcRadius startAngle:0 endAngle:2 * M_PI clockwise:NO]; | |
[path stroke]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CurveView.m | |
// UIBezierPathExampleForLI | |
// | |
// Created by Volodymyr Andriienko on 2/23/19. | |
// Copyright © 2019 VAndrJ. All rights reserved. | |
// | |
#import "CurveView.h" | |
@implementation CurveView | |
- (void)drawRect:(CGRect)rect { | |
[[UIColor blackColor] setStroke]; | |
let path = [UIBezierPath new]; | |
let lineWidth = rect.size.height / 30; | |
let beginPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect)); | |
let endPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect)); | |
let controlPoint1 = CGPointMake(CGRectGetMidX(rect) / 2, CGRectGetMinY(rect)); | |
let controlPoint2 = CGPointMake(CGRectGetMidX(rect) * 3 / 2, CGRectGetMaxY(rect)); | |
[path setLineWidth:lineWidth]; | |
[path moveToPoint:beginPoint]; | |
[path addCurveToPoint:endPoint controlPoint1:controlPoint1 controlPoint2:controlPoint2]; | |
[path stroke]; | |
let path1 = [UIBezierPath new]; | |
[path1 setLineWidth:rect.size.height / 60]; | |
[[[UIColor grayColor] colorWithAlphaComponent:0.25] setStroke]; | |
[path1 moveToPoint:beginPoint]; | |
[path1 addLineToPoint:controlPoint1]; | |
[path1 addLineToPoint:controlPoint2]; | |
[path1 addLineToPoint:endPoint]; | |
[path1 addLineToPoint:beginPoint]; | |
[path1 stroke]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// HeartView.m | |
// HeartView | |
// | |
// Created by Volodymyr Andriienko on 2/20/19. | |
// Copyright © 2019 VAndrJ. All rights reserved. | |
// | |
#import "HeartView.h" | |
@implementation HeartView | |
- (void)drawRect:(CGRect)rect { | |
[[UIColor redColor] setFill]; | |
[[self getHeartPathForRect:rect] fill]; | |
} | |
- (UIBezierPath *)getHeartPathForRect:(CGRect)rect { | |
let path = [UIBezierPath new]; | |
let leftCenterPoint = CGPointMake(CGRectGetMidX(rect) / 2, CGRectGetMidY(rect) / 2); | |
let rightCenterPoint = CGPointMake(CGRectGetMidX(rect) * 3 / 2, CGRectGetMidY(rect) / 2); | |
let arcRadius = rect.size.width / 4; | |
let bottomPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)); | |
let leftSidePoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect) / 2); | |
let leftSideControlPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect)); | |
let rightSidePoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect) / 2); | |
let rightSideControlPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect)); | |
[path addArcWithCenter:leftCenterPoint radius:arcRadius startAngle:0 endAngle: M_PI clockwise:NO]; | |
[path addArcWithCenter:rightCenterPoint radius:arcRadius startAngle:0 endAngle: M_PI clockwise:NO]; | |
[path moveToPoint:leftSidePoint]; | |
[path addQuadCurveToPoint:bottomPoint controlPoint:leftSideControlPoint]; | |
[path addQuadCurveToPoint:rightSidePoint controlPoint:rightSideControlPoint]; | |
[path closePath]; | |
return path; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LineView.m | |
// UIBezierPathExampleForLI | |
// | |
// Created by Volodymyr Andriienko on 2/23/19. | |
// Copyright © 2019 VAndrJ. All rights reserved. | |
// | |
#import "LineView.h" | |
@implementation LineView | |
- (void)drawRect:(CGRect)rect { | |
[[UIColor blackColor] setStroke]; | |
let path = [UIBezierPath new]; | |
let lineWidth = rect.size.height / 30; | |
let beginPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect)); | |
let endPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect)); | |
[path setLineWidth:lineWidth]; | |
[path moveToPoint:beginPoint]; | |
[path addLineToPoint:endPoint]; | |
[path stroke]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// QuadCurveView.m | |
// UIBezierPathExampleForLI | |
// | |
// Created by Volodymyr Andriienko on 2/23/19. | |
// Copyright © 2019 VAndrJ. All rights reserved. | |
// | |
#import "QuadCurveView.h" | |
@implementation QuadCurveView | |
- (void)drawRect:(CGRect)rect { | |
[[UIColor blackColor] setStroke]; | |
let path = [UIBezierPath new]; | |
let lineWidth = rect.size.height / 30; | |
let beginPoint = CGPointMake(CGRectGetMinX(rect), CGRectGetMidY(rect)); | |
let endPoint = CGPointMake(CGRectGetMaxX(rect), CGRectGetMidY(rect)); | |
let controlPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); | |
[path setLineWidth:lineWidth]; | |
[path moveToPoint:beginPoint]; | |
[path addQuadCurveToPoint:endPoint controlPoint:controlPoint]; | |
[path stroke]; | |
let path1 = [UIBezierPath new]; | |
[path1 setLineWidth:rect.size.height / 60]; | |
[[[UIColor grayColor] colorWithAlphaComponent:0.25] setStroke]; | |
[path1 moveToPoint:beginPoint]; | |
[path1 addLineToPoint:controlPoint]; | |
[path1 addLineToPoint:endPoint]; | |
[path1 addLineToPoint:beginPoint]; | |
[path1 stroke]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment