Last active
August 29, 2015 13:55
-
-
Save fjolnir/8783383 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
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSUInteger const mmWidth = 10; | |
CGSize const boundsSize = { mmWidth*10, 50 }; | |
UIGraphicsBeginImageContextWithOptions(boundsSize, NO, 0); | |
self.view.contentMode = UIViewContentModeTop; | |
[[UIColor blackColor] setFill]; | |
UIRectFill((CGRect) { | |
0, 0, | |
boundsSize.width, 0.5 | |
}); | |
for(NSUInteger x = 0; x < mmWidth*10; x += mmWidth) { | |
BOOL isCmMarker = x%(mmWidth*10) == 0; | |
float const width = isCmMarker ? 1.5 : 0.5; | |
UIRectFill((CGRect) { | |
floorf(x - width/2.0f) + 0.5f, | |
0, | |
width, | |
isCmMarker ? 15 : 10 | |
}); | |
} | |
self.view.backgroundColor = [UIColor colorWithPatternImage:UIGraphicsGetImageFromCurrentImageContext()]; | |
UIGraphicsEndImageContext(); | |
} |
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
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
_rulerLayer = [CAShapeLayer new]; | |
_rulerLayer.lineWidth = 1; | |
_rulerLayer.strokeColor = [UIColor blackColor].CGColor; | |
_mmLayer = [CAShapeLayer new]; | |
_mmLayer.lineWidth = 10; | |
_mmLayer.transform = CATransform3DMakeTranslation(0, _mmLayer.lineWidth/2.0f, 0); | |
_mmLayer.strokeColor = _rulerLayer.strokeColor; | |
_mmLayer.lineDashPattern = @[@0.5, @9.5]; | |
_cmLayer = [CAShapeLayer new]; | |
_cmLayer.lineWidth = 15; | |
_cmLayer.transform = CATransform3DMakeTranslation(0, _cmLayer.lineWidth/2.0f, 0); | |
_cmLayer.strokeColor = _rulerLayer.strokeColor; | |
_cmLayer.lineDashPattern = @[@1, @99]; | |
[self.view.layer addSublayer:_rulerLayer]; | |
[_rulerLayer addSublayer:_mmLayer]; | |
[_rulerLayer addSublayer:_cmLayer]; | |
} | |
- (void)viewDidLayoutSubviews | |
{ | |
UIBezierPath * const rulerPath = [UIBezierPath bezierPath]; | |
[rulerPath moveToPoint:(CGPoint) { 0, 100 }]; | |
[rulerPath addLineToPoint:(CGPoint) { self.view.bounds.size.width, 100 }]; | |
_rulerLayer.path = [[rulerPath copy] CGPath]; | |
_mmLayer.path = [[rulerPath copy] CGPath]; | |
_cmLayer.path = [[rulerPath copy] CGPath]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment