Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.30 KB | None | 0 0
  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface ViewControllerImage : UIViewController {
  4. IBOutlet UILabel *datum;
  5. IBOutlet UILabel *debug;
  6. }
  7.  
  8. @property (nonatomic, assign) double thicknessValue1;
  9. @property (nonatomic, assign) double capWidthValue1;
  10. @end
  11.  
  12. - (void)viewDidLoad
  13. {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. [datum setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
  17.  
  18. NSString *value = [[NSString alloc] initWithFormat:@"%f", self.thicknessValue1];
  19.  
  20. debug.text = value;
  21.  
  22. draw2D *myView = [[draw2D alloc]initWithThickness: self.thicknessValue1 andCapWidth: self.capWidthValue1];
  23.  
  24. NSLog(@"First Logs");
  25. NSLog(@"%f",myView.thicknessValue2);
  26. NSLog(@"%f",myView.capWidthValue2);
  27. NSLog(@"END FIRST LOGS");
  28. }
  29.  
  30. @interface draw2D : UIView
  31.  
  32. - (id)initWithThickness:(double)thickness andCapWidth:(double)capWith;
  33.  
  34.  
  35. @property (nonatomic, assign) double thicknessValue2;
  36. @property (nonatomic, assign) double capWidthValue2;
  37.  
  38. @end
  39.  
  40. #import <UIKit/UIKit.h>
  41.  
  42. @interface draw2D : UIView
  43.  
  44. - (id)initWithThickness:(double)thickness andCapWidth:(double)capWith
  45. {
  46. self = [super init];
  47. if(self)
  48. {
  49. thicknessValue2 = self.thicknessValue2;
  50. capWidthValue2 = self.capWidthValue2;
  51. NSLog(@"Second Logs");
  52. NSLog(@"%f",thicknessValue2);
  53. NSLog(@"%f",capWidthValue2);
  54. NSLog(@"END Second LOGS");
  55. }
  56. return self;
  57. }
  58.  
  59. - (void)drawRect:(CGRect)rect {
  60.  
  61.  
  62. NSLog(@"Third Logs");
  63. NSLog(@"%f",self.thicknessValue2);
  64. NSLog(@"%f",self.capWidthValue2);
  65. NSLog(@"END Third LOGS");
  66.  
  67. //thickness = self.thicknessValue2;
  68. //capWidth = self.capWidthValue2;
  69.  
  70. double thickness = thicknessValue2;
  71. double capWidth = capWidthValue2;
  72.  
  73. double weldCentreLine = 285;
  74. double centreLine = 160;
  75. double surface = centreLine + (thickness / 2);
  76. double bottom = centreLine - (thickness / 2);
  77.  
  78. double datumSideCap = weldCentreLine - (capWidth / 2);
  79. double oppositeSideCap = weldCentreLine + (capWidth / 2);
  80.  
  81.  
  82. double datumSideCapCap = weldCentreLine - (capWidth / 2) - 10;
  83. double oppositeSideCapCap = weldCentreLine + (capWidth / 2) + 10;
  84.  
  85. double beforeRoot = bottom + 5;
  86.  
  87. double capHeight = surface + (thickness / 3);
  88.  
  89. double capDifferenceRound = (oppositeSideCap - datumSideCap) / 2;
  90.  
  91. //Obtain graphics context of the view
  92. CGContextRef context0 = UIGraphicsGetCurrentContext();
  93.  
  94. //Width of the line
  95. CGContextSetLineWidth(context0, 2.0);
  96.  
  97. //Color Space
  98. CGColorSpaceRef colorspace0 = CGColorSpaceCreateDeviceRGB();
  99. //Colors
  100. CGFloat components0[] = {0.0, 0.0, 0.0, 0.1};
  101. //Creates color
  102. CGColorRef color0 = CGColorCreate(colorspace0, components0);
  103. //What color is used?
  104. CGContextSetStrokeColorWithColor(context0, color0);
  105.  
  106. //WELD CENTRELINE
  107. CGContextMoveToPoint(context0, 320, 285);
  108. CGContextAddLineToPoint(context0, 300, 285);
  109. CGContextMoveToPoint(context0, 280, 285);
  110. CGContextAddLineToPoint(context0, 260, 285);
  111. CGContextMoveToPoint(context0, 240, 285);
  112. CGContextAddLineToPoint(context0, 220, 285);
  113. CGContextMoveToPoint(context0, 200, 285);
  114. CGContextAddLineToPoint(context0, 180, 285);
  115. CGContextMoveToPoint(context0, 160, 285);
  116. CGContextAddLineToPoint(context0, 140, 285);
  117. CGContextMoveToPoint(context0, 120, 285);
  118. CGContextAddLineToPoint(context0, 100, 285);
  119. CGContextMoveToPoint(context0, 80, 285);
  120. CGContextAddLineToPoint(context0, 60, 285);
  121. CGContextMoveToPoint(context0, 40, 285);
  122. CGContextAddLineToPoint(context0, 20, 285);
  123. //END WELD CENTRELINE
  124.  
  125.  
  126. //Draws the line
  127. CGContextStrokePath(context0);
  128. CGColorSpaceRelease(colorspace0);
  129. CGColorRelease(color0);
  130.  
  131.  
  132.  
  133. //Obtain graphics context of the view
  134. CGContextRef context = UIGraphicsGetCurrentContext();
  135.  
  136. //Width of the line
  137. CGContextSetLineWidth(context, 2.0);
  138.  
  139. //Color Space
  140. CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
  141. //Colors
  142. CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
  143. //Creates color
  144. CGColorRef color = CGColorCreate(colorspace, components);
  145. //What color is used?
  146. CGContextSetStrokeColorWithColor(context, color);
  147.  
  148. //Start point
  149.  
  150. //WELD START LEFT
  151. CGContextMoveToPoint(context, surface, 0);
  152. CGContextAddLineToPoint(context, surface, datumSideCap);
  153. CGContextAddLineToPoint(context, beforeRoot, (weldCentreLine-5));
  154. CGContextAddLineToPoint(context, bottom, (weldCentreLine-5));
  155. CGContextAddLineToPoint(context, bottom, 0);
  156. //END WELD START LEFT
  157.  
  158. //WELD START RIGHT
  159. CGContextMoveToPoint(context, surface, 570);
  160. CGContextAddLineToPoint(context, surface, oppositeSideCap);
  161. CGContextAddLineToPoint(context, beforeRoot, (weldCentreLine+5));
  162. CGContextAddLineToPoint(context, bottom, (weldCentreLine+5));
  163. CGContextAddLineToPoint(context, bottom, 570);
  164. //END WELD START RIGHT
  165.  
  166. //WELD CAP START POINT
  167. CGContextMoveToPoint(context, surface, datumSideCapCap);
  168. CGContextAddArcToPoint(context, capHeight,weldCentreLine, surface,oppositeSideCap, capDifferenceRound);
  169. CGContextAddLineToPoint(context, surface, oppositeSideCapCap);
  170. //WELD CAP END POINT
  171.  
  172. //ROOT CAP START POINT
  173. CGContextMoveToPoint(context, bottom, 270);
  174. CGContextAddArcToPoint(context, (bottom - 15),280, (bottom - 15),283, 10);
  175. CGContextMoveToPoint(context, bottom, 300);
  176. CGContextAddArcToPoint(context, (bottom - 15),290, (bottom - 15),287, 10);
  177. //ROOT CAP END POINT
  178. //End Points
  179.  
  180. //Draws the line
  181. CGContextStrokePath(context);
  182. CGColorSpaceRelease(colorspace);
  183. CGColorRelease(color);
  184.  
  185. //DEFECT
  186.  
  187. //Obtain graphics context of the view
  188. CGContextRef context1 = UIGraphicsGetCurrentContext();
  189.  
  190. //Width of the line
  191. CGContextSetLineWidth(context1, 2.0);
  192.  
  193. //Color Space
  194. CGColorSpaceRef colorspace1 = CGColorSpaceCreateDeviceRGB();
  195. //Colors
  196. CGFloat components1[] = {1.0, 0.0, 0.0, 1.0};
  197. //Creates color
  198. CGColorRef color1 = CGColorCreate(colorspace1, components1);
  199. //What color is used?
  200. CGContextSetStrokeColorWithColor(context1, color1);
  201.  
  202. //DRAW DEFECT
  203. CGContextMoveToPoint(context, 160, 285);
  204. CGContextAddLineToPoint(context, 159, 286);
  205. CGContextAddLineToPoint(context, 158, 285);
  206. CGContextAddLineToPoint(context, 159, 284);
  207. CGContextAddLineToPoint(context, 160, 285);
  208.  
  209. //Draws the line
  210. CGContextStrokePath(context1);
  211. CGColorSpaceRelease(colorspace1);
  212. CGColorRelease(color1);
  213.  
  214. }
  215.  
  216.  
  217.  
  218.  
  219. @end
  220.  
  221. - (id)initWithThickness:(double)thickness andCapWidth:(double)capWith
  222. {
  223. self = [super init];
  224. if(self)
  225. {
  226. self.thickness = thickness;
  227. self.capWidth = capWidth;
  228. }
  229. return self;
  230. }
  231.  
  232. draw2D *myView = [[draw2D alloc]initWithThickness: self.thicknessValue1 andCapWidth: self.capWidthValue1];
  233.  
  234. draw2D *myView = [[draw2D alloc]initWithThickness: self.thicknessValue1 andCapWidth: self.capWidthValue1];
  235.  
  236. - (id)initWithThickness:(double)thickness andCapWidth:(double)capWith
  237. {
  238. self = [super init];
  239. if(self)
  240. {
  241. thicknessValue2 = self.thicknessValue2;
  242. capWidthValue2 = self.capWidthValue2;
  243.  
  244. double thickness = thicknessValue2;
  245. double capWidth = capWidthValue2;
  246.  
  247. - (void)viewDidLoad
  248. {
  249. [super viewDidLoad];
  250. // Do any additional setup after loading the view.
  251. [datum setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
  252.  
  253. NSString *value = [[NSString alloc] initWithFormat:@"%f", self.thicknessValue1];
  254.  
  255. debug.text = value;
  256.  
  257. draw2D *myView = [[draw2D alloc]initWithThickness: self.thicknessValue1 andCapWidth: self.capWidthValue1];
  258.  
  259. // Now it will not go out of scope, as it will be added to the
  260. // viewControllers view property
  261. [self.view addSubview:myview];
  262.  
  263. NSLog(@"First Logs");
  264. NSLog(@"%f",myView.thicknessValue2);
  265. NSLog(@"%f",myView.capWidthValue2);
  266. NSLog(@"END FIRST LOGS");
  267. }
  268.  
  269. - (void)viewDidLoad
  270. {
  271. [super viewDidLoad];
  272.  
  273. NSLog(@"Before init");
  274. Draw2d *myView = [[Draw2d alloc] initWithFrame:CGRectMake(0, 0, 320, 320) thickness:15.0 capwidth:17.5];
  275. NSLog(@"After init");
  276. [self.view addSubview:myView];
  277. NSLog(@"After placing on superview at x= 0, y = 0, width = 320, height = 320");
  278. }
  279.  
  280. #import <UIKit/UIKit.h>
  281.  
  282. @interface Draw2d : UIView
  283.  
  284. @property (nonatomic, assign) double thickness;
  285. @property (nonatomic, assign) double capWidth;
  286.  
  287. - (id)initWithFrame:(CGRect)frame thickness:(double)thickness capwidth:(double)capWidth;
  288.  
  289. @end
  290.  
  291. #import "Draw2d.h"
  292.  
  293. @implementation Draw2d
  294.  
  295. - (id)initWithFrame:(CGRect)frame
  296. {
  297. self = [super initWithFrame:frame];
  298. if (self) {
  299. // Initialization code
  300. }
  301. return self;
  302. }
  303.  
  304. - (id)initWithFrame:(CGRect)frame thickness:(double)thickness capwidth:(double)capWidth
  305. {
  306. self = [super initWithFrame:frame];
  307. if(self)
  308. {
  309. // Left side is property in .h
  310. // right side is the parameters passed into method
  311. self.thickness = thickness;
  312. self.capWidth = capWidth;
  313. }
  314. return self;
  315. }
  316.  
  317. - (void)drawRect:(CGRect)rect
  318. {
  319. NSLog(@"Passed in thickness: %f", self.thickness);
  320. NSLog(@"Passed in capWidth: %f", self.capWidth);
  321. }
  322.  
  323.  
  324. @end
  325.  
  326. 2014-04-16 09:23:23.613 Before init
  327. 2014-04-16 09:23:23.613 After init
  328. 2014-04-16 09:23:23.613 After placing on superview at x= 0, y = 0, width = 320, height = 320
  329. 2014-04-16 09:23:23.615 Passed in thickness: 15.000000
  330. 2014-04-16 09:23:23.616 Passed in capWidth: 17.500000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement