Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <UIKit/UIKit.h>
- @interface ViewControllerImage : UIViewController {
- IBOutlet UILabel *datum;
- IBOutlet UILabel *debug;
- }
- @property (nonatomic, assign) double thicknessValue1;
- @property (nonatomic, assign) double capWidthValue1;
- @end
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [datum setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
- NSString *value = [[NSString alloc] initWithFormat:@"%f", self.thicknessValue1];
- debug.text = value;
- draw2D *myView = [[draw2D alloc]initWithThickness: self.thicknessValue1 andCapWidth: self.capWidthValue1];
- NSLog(@"First Logs");
- NSLog(@"%f",myView.thicknessValue2);
- NSLog(@"%f",myView.capWidthValue2);
- NSLog(@"END FIRST LOGS");
- }
- @interface draw2D : UIView
- - (id)initWithThickness:(double)thickness andCapWidth:(double)capWith;
- @property (nonatomic, assign) double thicknessValue2;
- @property (nonatomic, assign) double capWidthValue2;
- @end
- #import <UIKit/UIKit.h>
- @interface draw2D : UIView
- - (id)initWithThickness:(double)thickness andCapWidth:(double)capWith
- {
- self = [super init];
- if(self)
- {
- thicknessValue2 = self.thicknessValue2;
- capWidthValue2 = self.capWidthValue2;
- NSLog(@"Second Logs");
- NSLog(@"%f",thicknessValue2);
- NSLog(@"%f",capWidthValue2);
- NSLog(@"END Second LOGS");
- }
- return self;
- }
- - (void)drawRect:(CGRect)rect {
- NSLog(@"Third Logs");
- NSLog(@"%f",self.thicknessValue2);
- NSLog(@"%f",self.capWidthValue2);
- NSLog(@"END Third LOGS");
- //thickness = self.thicknessValue2;
- //capWidth = self.capWidthValue2;
- double thickness = thicknessValue2;
- double capWidth = capWidthValue2;
- double weldCentreLine = 285;
- double centreLine = 160;
- double surface = centreLine + (thickness / 2);
- double bottom = centreLine - (thickness / 2);
- double datumSideCap = weldCentreLine - (capWidth / 2);
- double oppositeSideCap = weldCentreLine + (capWidth / 2);
- double datumSideCapCap = weldCentreLine - (capWidth / 2) - 10;
- double oppositeSideCapCap = weldCentreLine + (capWidth / 2) + 10;
- double beforeRoot = bottom + 5;
- double capHeight = surface + (thickness / 3);
- double capDifferenceRound = (oppositeSideCap - datumSideCap) / 2;
- //Obtain graphics context of the view
- CGContextRef context0 = UIGraphicsGetCurrentContext();
- //Width of the line
- CGContextSetLineWidth(context0, 2.0);
- //Color Space
- CGColorSpaceRef colorspace0 = CGColorSpaceCreateDeviceRGB();
- //Colors
- CGFloat components0[] = {0.0, 0.0, 0.0, 0.1};
- //Creates color
- CGColorRef color0 = CGColorCreate(colorspace0, components0);
- //What color is used?
- CGContextSetStrokeColorWithColor(context0, color0);
- //WELD CENTRELINE
- CGContextMoveToPoint(context0, 320, 285);
- CGContextAddLineToPoint(context0, 300, 285);
- CGContextMoveToPoint(context0, 280, 285);
- CGContextAddLineToPoint(context0, 260, 285);
- CGContextMoveToPoint(context0, 240, 285);
- CGContextAddLineToPoint(context0, 220, 285);
- CGContextMoveToPoint(context0, 200, 285);
- CGContextAddLineToPoint(context0, 180, 285);
- CGContextMoveToPoint(context0, 160, 285);
- CGContextAddLineToPoint(context0, 140, 285);
- CGContextMoveToPoint(context0, 120, 285);
- CGContextAddLineToPoint(context0, 100, 285);
- CGContextMoveToPoint(context0, 80, 285);
- CGContextAddLineToPoint(context0, 60, 285);
- CGContextMoveToPoint(context0, 40, 285);
- CGContextAddLineToPoint(context0, 20, 285);
- //END WELD CENTRELINE
- //Draws the line
- CGContextStrokePath(context0);
- CGColorSpaceRelease(colorspace0);
- CGColorRelease(color0);
- //Obtain graphics context of the view
- CGContextRef context = UIGraphicsGetCurrentContext();
- //Width of the line
- CGContextSetLineWidth(context, 2.0);
- //Color Space
- CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
- //Colors
- CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
- //Creates color
- CGColorRef color = CGColorCreate(colorspace, components);
- //What color is used?
- CGContextSetStrokeColorWithColor(context, color);
- //Start point
- //WELD START LEFT
- CGContextMoveToPoint(context, surface, 0);
- CGContextAddLineToPoint(context, surface, datumSideCap);
- CGContextAddLineToPoint(context, beforeRoot, (weldCentreLine-5));
- CGContextAddLineToPoint(context, bottom, (weldCentreLine-5));
- CGContextAddLineToPoint(context, bottom, 0);
- //END WELD START LEFT
- //WELD START RIGHT
- CGContextMoveToPoint(context, surface, 570);
- CGContextAddLineToPoint(context, surface, oppositeSideCap);
- CGContextAddLineToPoint(context, beforeRoot, (weldCentreLine+5));
- CGContextAddLineToPoint(context, bottom, (weldCentreLine+5));
- CGContextAddLineToPoint(context, bottom, 570);
- //END WELD START RIGHT
- //WELD CAP START POINT
- CGContextMoveToPoint(context, surface, datumSideCapCap);
- CGContextAddArcToPoint(context, capHeight,weldCentreLine, surface,oppositeSideCap, capDifferenceRound);
- CGContextAddLineToPoint(context, surface, oppositeSideCapCap);
- //WELD CAP END POINT
- //ROOT CAP START POINT
- CGContextMoveToPoint(context, bottom, 270);
- CGContextAddArcToPoint(context, (bottom - 15),280, (bottom - 15),283, 10);
- CGContextMoveToPoint(context, bottom, 300);
- CGContextAddArcToPoint(context, (bottom - 15),290, (bottom - 15),287, 10);
- //ROOT CAP END POINT
- //End Points
- //Draws the line
- CGContextStrokePath(context);
- CGColorSpaceRelease(colorspace);
- CGColorRelease(color);
- //DEFECT
- //Obtain graphics context of the view
- CGContextRef context1 = UIGraphicsGetCurrentContext();
- //Width of the line
- CGContextSetLineWidth(context1, 2.0);
- //Color Space
- CGColorSpaceRef colorspace1 = CGColorSpaceCreateDeviceRGB();
- //Colors
- CGFloat components1[] = {1.0, 0.0, 0.0, 1.0};
- //Creates color
- CGColorRef color1 = CGColorCreate(colorspace1, components1);
- //What color is used?
- CGContextSetStrokeColorWithColor(context1, color1);
- //DRAW DEFECT
- CGContextMoveToPoint(context, 160, 285);
- CGContextAddLineToPoint(context, 159, 286);
- CGContextAddLineToPoint(context, 158, 285);
- CGContextAddLineToPoint(context, 159, 284);
- CGContextAddLineToPoint(context, 160, 285);
- //Draws the line
- CGContextStrokePath(context1);
- CGColorSpaceRelease(colorspace1);
- CGColorRelease(color1);
- }
- @end
- - (id)initWithThickness:(double)thickness andCapWidth:(double)capWith
- {
- self = [super init];
- if(self)
- {
- self.thickness = thickness;
- self.capWidth = capWidth;
- }
- return self;
- }
- draw2D *myView = [[draw2D alloc]initWithThickness: self.thicknessValue1 andCapWidth: self.capWidthValue1];
- draw2D *myView = [[draw2D alloc]initWithThickness: self.thicknessValue1 andCapWidth: self.capWidthValue1];
- - (id)initWithThickness:(double)thickness andCapWidth:(double)capWith
- {
- self = [super init];
- if(self)
- {
- thicknessValue2 = self.thicknessValue2;
- capWidthValue2 = self.capWidthValue2;
- double thickness = thicknessValue2;
- double capWidth = capWidthValue2;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [datum setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
- NSString *value = [[NSString alloc] initWithFormat:@"%f", self.thicknessValue1];
- debug.text = value;
- draw2D *myView = [[draw2D alloc]initWithThickness: self.thicknessValue1 andCapWidth: self.capWidthValue1];
- // Now it will not go out of scope, as it will be added to the
- // viewControllers view property
- [self.view addSubview:myview];
- NSLog(@"First Logs");
- NSLog(@"%f",myView.thicknessValue2);
- NSLog(@"%f",myView.capWidthValue2);
- NSLog(@"END FIRST LOGS");
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSLog(@"Before init");
- Draw2d *myView = [[Draw2d alloc] initWithFrame:CGRectMake(0, 0, 320, 320) thickness:15.0 capwidth:17.5];
- NSLog(@"After init");
- [self.view addSubview:myView];
- NSLog(@"After placing on superview at x= 0, y = 0, width = 320, height = 320");
- }
- #import <UIKit/UIKit.h>
- @interface Draw2d : UIView
- @property (nonatomic, assign) double thickness;
- @property (nonatomic, assign) double capWidth;
- - (id)initWithFrame:(CGRect)frame thickness:(double)thickness capwidth:(double)capWidth;
- @end
- #import "Draw2d.h"
- @implementation Draw2d
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- }
- return self;
- }
- - (id)initWithFrame:(CGRect)frame thickness:(double)thickness capwidth:(double)capWidth
- {
- self = [super initWithFrame:frame];
- if(self)
- {
- // Left side is property in .h
- // right side is the parameters passed into method
- self.thickness = thickness;
- self.capWidth = capWidth;
- }
- return self;
- }
- - (void)drawRect:(CGRect)rect
- {
- NSLog(@"Passed in thickness: %f", self.thickness);
- NSLog(@"Passed in capWidth: %f", self.capWidth);
- }
- @end
- 2014-04-16 09:23:23.613 Before init
- 2014-04-16 09:23:23.613 After init
- 2014-04-16 09:23:23.613 After placing on superview at x= 0, y = 0, width = 320, height = 320
- 2014-04-16 09:23:23.615 Passed in thickness: 15.000000
- 2014-04-16 09:23:23.616 Passed in capWidth: 17.500000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement