Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- Definition of constants for better clarity.
- Implementation of UII…

…mage resizing if necessary.
- Maximum height and width checked agains the UIView bounds and not the screen dimensions as it was incorrectly assuming.
- Number of lines now calculated depending of the height of the containing view.
  • Loading branch information...
commit 825858c40a16231a18c6fd633b5c18750b78a023 1 parent 0c6f8e1
Afrael Ortiz authored
3  OANotebookView.h
@@ -9,6 +9,9 @@
9 9
 #import <UIKit/UIKit.h>
10 10
 #import <QuartzCore/QuartzCore.h>
11 11
 
  12
+#define MAX_SCREEN_HEIGHT 480;
  13
+#define DEFAULT_PAPER_TEXTURE @"paper"
  14
+
12 15
 @interface OANotebookView : UIView{
13 16
     
14 17
 }
29  OANotebookView.m
@@ -36,12 +36,17 @@ - (void)drawRect:(CGRect)rect
36 36
 }
37 37
 
38 38
 - (UIImage *) patternImageOfSize:(CGSize) size{
39  
-    UIImage *image = [UIImage imageNamed:@"paper"];
  39
+    UIImage *image = [UIImage imageNamed:DEFAULT_PAPER_TEXTURE];
  40
+    UIGraphicsBeginImageContext(size);
  41
+    if((image.size.height * image.size.width) > (size.height * size.width)){
  42
+        [image drawInRect:CGRectMake(0.0, 0.0, size.width, size.height)];
  43
+    }
  44
+    UIGraphicsEndImageContext();
40 45
     return image;
41 46
 }
42 47
 
43 48
 - (void) setBackgroundTexture{
44  
-    UIImage *paperPatternImage = [self patternImageOfSize:CGSizeMake(32.0, 32.0)];
  49
+    UIImage *paperPatternImage = [self patternImageOfSize:CGSizeMake(24.0, 24.0)];
45 50
     [[UIColor colorWithPatternImage:paperPatternImage] setFill];
46 51
     UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
47 52
     [path fill];
@@ -49,20 +54,20 @@ - (void) setBackgroundTexture{
49 54
 
50 55
 - (void) drawHorizonalBlueLines: (CGContextRef) ctx{
51 56
     CGContextSaveGState(ctx);
52  
-    CGRect screenRect = [[UIScreen mainScreen] bounds];
53  
-    CGFloat screenWidth = screenRect.size.width;    
54  
-    screenWidth -= 10;
  57
+    CGRect viewRect = self.bounds;
  58
+    CGFloat viewWidth = viewRect.size.width;    
55 59
     UIColor *lineColor = [UIColor colorWithRed:0/255.0 
56 60
                                          green:124.0/255.0
57 61
                                           blue:255.0/255.0 
58 62
                                          alpha:0.5];
59 63
     UIBezierPath *path = [UIBezierPath bezierPath];
60 64
     [path moveToPoint:CGPointMake(10, 40.5)];
61  
-    [path addLineToPoint:CGPointMake(screenWidth, 40.5)];
  65
+    [path addLineToPoint:CGPointMake(viewWidth, 40.5)];
62 66
     [path setLineWidth:1.0];
63 67
     [lineColor setStroke];
64 68
     [path stroke];
65  
-    for (int i = 0; i < 9; i++) {
  69
+    int numberOfLines = (viewRect.size.height - 80) / 40 ;
  70
+    for (int i = 0; i < numberOfLines; i++) {
66 71
         CGContextTranslateCTM(ctx, 0.0, (40 + i));
67 72
         [path stroke];
68 73
     }
@@ -70,21 +75,21 @@ - (void) drawHorizonalBlueLines: (CGContextRef) ctx{
70 75
 }
71 76
 
72 77
 - (void) drawVerticalMarginLine{
73  
-    CGRect screenRect = [[UIScreen mainScreen] bounds];
74  
-    CGFloat screenHeight = screenRect.size.height;    
75  
-    screenHeight -= 2;
  78
+    CGRect viewRect = self.bounds;
  79
+    CGFloat viewHeight = viewRect.size.height;    
  80
+    viewHeight -= 2;
76 81
     UIColor *lineColor = [UIColor colorWithRed:255.0/255.0 
77 82
                                          green:142.0/255.0
78 83
                                           blue:142.0/255.0 
79 84
                                          alpha:0.5];
80 85
     UIBezierPath *path = [UIBezierPath bezierPath];
81 86
     [path moveToPoint:CGPointMake(40.5, 2.0)];
82  
-    [path addLineToPoint:CGPointMake(40.5, (screenHeight -2))];
  87
+    [path addLineToPoint:CGPointMake(40.5, (viewHeight -2))];
83 88
     [path setLineWidth:1.0];
84 89
     [lineColor setStroke];
85 90
     [path stroke];
86 91
     [path moveToPoint:CGPointMake(42.5, 2.0)];
87  
-    [path addLineToPoint:CGPointMake(42.5, (screenHeight -2))];
  92
+    [path addLineToPoint:CGPointMake(42.5, (viewHeight -2))];
88 93
     [path stroke];
89 94
 }
90 95
 
36  OANotebookViewDemo/en.lproj/FlipsideViewController.xib
@@ -47,6 +47,7 @@
47 47
 						<string key="NSFrameSize">{320, 44}</string>
48 48
 						<reference key="NSSuperview" ref="249263867"/>
49 49
 						<reference key="NSWindow"/>
  50
+						<reference key="NSNextKeyView" ref="789052842"/>
50 51
 						<bool key="IBUIOpaque">NO</bool>
51 52
 						<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
52 53
 						<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
@@ -66,16 +67,31 @@
66 67
 							</object>
67 68
 						</object>
68 69
 					</object>
  70
+					<object class="IBUIView" id="789052842">
  71
+						<reference key="NSNextResponder" ref="249263867"/>
  72
+						<int key="NSvFlags">274</int>
  73
+						<string key="NSFrame">{{17, 117}, {286, 226}}</string>
  74
+						<reference key="NSSuperview" ref="249263867"/>
  75
+						<reference key="NSWindow"/>
  76
+						<reference key="NSNextKeyView"/>
  77
+						<object class="NSColor" key="IBUIBackgroundColor">
  78
+							<int key="NSColorSpace">3</int>
  79
+							<bytes key="NSWhite">MQA</bytes>
  80
+							<object class="NSColorSpace" key="NSCustomColorSpace" id="148956950">
  81
+								<int key="NSID">2</int>
  82
+							</object>
  83
+						</object>
  84
+						<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
  85
+					</object>
69 86
 				</object>
70 87
 				<string key="NSFrame">{{0, 20}, {320, 460}}</string>
71 88
 				<reference key="NSSuperview"/>
72 89
 				<reference key="NSWindow"/>
  90
+				<reference key="NSNextKeyView" ref="871675769"/>
73 91
 				<object class="NSColor" key="IBUIBackgroundColor">
74 92
 					<int key="NSColorSpace">3</int>
75 93
 					<bytes key="NSWhite">MC4yNQA</bytes>
76  
-					<object class="NSColorSpace" key="NSCustomColorSpace">
77  
-						<int key="NSID">2</int>
78  
-					</object>
  94
+					<reference key="NSCustomColorSpace" ref="148956950"/>
79 95
 				</object>
80 96
 				<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
81 97
 				<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics">
@@ -132,6 +148,7 @@
132 148
 						<object class="NSMutableArray" key="children">
133 149
 							<bool key="EncodedWithXMLCoder">YES</bool>
134 150
 							<reference ref="871675769"/>
  151
+							<reference ref="789052842"/>
135 152
 						</object>
136 153
 						<reference key="parent" ref="0"/>
137 154
 					</object>
@@ -158,6 +175,11 @@
158 175
 						<reference key="object" ref="854562692"/>
159 176
 						<reference key="parent" ref="553200710"/>
160 177
 					</object>
  178
+					<object class="IBObjectRecord">
  179
+						<int key="objectID">48</int>
  180
+						<reference key="object" ref="789052842"/>
  181
+						<reference key="parent" ref="249263867"/>
  182
+					</object>
161 183
 				</object>
162 184
 			</object>
163 185
 			<object class="NSMutableDictionary" key="flattenedProperties">
@@ -168,11 +190,12 @@
168 190
 					<string>-1.IBPluginDependency</string>
169 191
 					<string>-2.CustomClassName</string>
170 192
 					<string>-2.IBPluginDependency</string>
171  
-					<string>40.CustomClassName</string>
172 193
 					<string>40.IBPluginDependency</string>
173 194
 					<string>42.IBPluginDependency</string>
174 195
 					<string>43.IBPluginDependency</string>
175 196
 					<string>44.IBPluginDependency</string>
  197
+					<string>48.CustomClassName</string>
  198
+					<string>48.IBPluginDependency</string>
176 199
 				</object>
177 200
 				<object class="NSMutableArray" key="dict.values">
178 201
 					<bool key="EncodedWithXMLCoder">YES</bool>
@@ -180,11 +203,12 @@
180 203
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
181 204
 					<string>UIResponder</string>
182 205
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
183  
-					<string>OANotebookView</string>
184 206
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
185 207
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
186 208
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
187 209
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
  210
+					<string>OANotebookView</string>
  211
+					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
188 212
 				</object>
189 213
 			</object>
190 214
 			<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -199,7 +223,7 @@
199 223
 				<reference key="dict.values" ref="0"/>
200 224
 			</object>
201 225
 			<nil key="sourceID"/>
202  
-			<int key="maxID">46</int>
  226
+			<int key="maxID">48</int>
203 227
 		</object>
204 228
 		<object class="IBClassDescriber" key="IBDocument.Classes">
205 229
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">

0 notes on commit 825858c

Please sign in to comment.
Something went wrong with that request. Please try again.