Advertisement
Guest User

Untitled

a guest
May 23rd, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. //
  2. // MyLineDrawingView.h
  3. // DrawLines
  4. //
  5. // Created by Reetu Raj on 11/05/11.
  6. // Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10.  
  11.  
  12. @interface MyLineDrawingView : UIView {
  13.  
  14. UIBezierPath *myPath;
  15. UIColor *brushPattern;
  16. }
  17.  
  18. @end
  19.  
  20.  
  21.  
  22. //
  23. // MyLineDrawingView.m
  24. // DrawLines
  25. //
  26. // Created by Reetu Raj on 11/05/11.
  27. // Copyright 2011 __MyCompanyName__. All rights reserved.
  28. //
  29.  
  30. #import "MyLineDrawingView.h"
  31.  
  32.  
  33. @implementation MyLineDrawingView
  34.  
  35. - (id)initWithFrame:(CGRect)frame
  36. {
  37. self = [super initWithFrame:frame];
  38. if (self) {
  39. // Initialization code
  40.  
  41. self.backgroundColor=[UIColor whiteColor];
  42. myPath=[[UIBezierPath alloc]init];
  43. myPath.lineCapStyle=kCGLineCapRound;
  44. myPath.miterLimit=0;
  45. myPath.lineWidth=10;
  46. brushPattern=[UIColor redColor];
  47.  
  48.  
  49.  
  50. }
  51. return self;
  52. }
  53.  
  54.  
  55. // Only override drawRect: if you perform custom drawing.
  56. // An empty implementation adversely affects performance during animation.
  57. - (void)drawRect:(CGRect)rect
  58. {
  59. [brushPattern setStroke];
  60. [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
  61. // Drawing code
  62. //[myPath stroke];
  63. }
  64.  
  65. #pragma mark - Touch Methods
  66. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  67. {
  68.  
  69. UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
  70. [myPath moveToPoint:[mytouch locationInView:self]];
  71.  
  72. }
  73. -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  74. {
  75.  
  76. UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
  77. [myPath addLineToPoint:[mytouch locationInView:self]];
  78. [self setNeedsDisplay];
  79.  
  80. }
  81. -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  82. {
  83.  
  84.  
  85.  
  86. }
  87.  
  88. - (void)dealloc
  89. {
  90. [brushPattern release];
  91. [super dealloc];
  92. }
  93.  
  94. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement