Last active
August 29, 2015 14:22
-
-
Save mmuszynski/ae811aba51d05d3ce131 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
// | |
// MusicStaffViewStaffLayer.swift | |
// MusicStaffView | |
// | |
// Created by Mike Muszynski on 1/4/15. | |
// Copyright (c) 2015 Mike Muszynski. All rights reserved. | |
// | |
import UIKit | |
class MusicStaffViewStaffLayer: CAShapeLayer { | |
var maxLedgerLines : Int = 0 | |
var currentHorizontalPosition : CGFloat { | |
get { | |
let sublayers = self.sublayers | |
guard sublayers != nil else { | |
return 0 | |
} | |
let lastElement = sublayers!.last as CALayer! | |
return lastElement.frame.origin.x + lastElement.frame.size.width | |
} | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
strokeColor = UIColor.blackColor().CGColor | |
} | |
override init() { | |
super.init() | |
strokeColor = UIColor.blackColor().CGColor | |
} | |
override var path : CGPath? { | |
get { | |
return staffPath() | |
} | |
set { | |
} | |
} | |
func staffPath() -> CGPathRef { | |
let staffLines = UIBezierPath() | |
let spaceWidth : CGFloat = self.bounds.size.height / (6.0 + 2.0 * CGFloat(maxLedgerLines)) | |
self.lineWidth = spaceWidth / 10.0 | |
for i in 1...(5 + maxLedgerLines) { | |
if (i <= maxLedgerLines || i > 5 + maxLedgerLines) { | |
continue | |
} | |
let height = self.bounds.origin.y + spaceWidth * CGFloat(i) | |
staffLines.moveToPoint(CGPointMake(self.bounds.origin.x, height)) | |
staffLines.addLineToPoint(CGPointMake(self.bounds.origin.x + self.bounds.size.width, height)) | |
} | |
return staffLines.CGPath | |
} | |
} |
lilyball
commented
Jun 10, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment