我有一个名为Chord子类的类UILabel:
import UIKit
class Chord: UILabel {
var numTextLine: Int?
var positionInTextLine: CGFloat?
var tempPosInLine: CGFloat?
init(chordName: String, dLine: DLine, xAxis: CGFloat, posInTextLine: CGFloat) {
// posInLine: CGFloat
let labelSize = chordName.sizeWithAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14.0)])
let labelPositionY = ((dLine.upLine.frame.height) - labelSize.height) / 2
super.init(frame: CGRect(origin: CGPoint(x: xAxis, y: labelPositionY), size: labelSize))
self.numTextLine = dLine.numTextLine
self.positionInTextLine = posInTextLine
self.tempPosInLine = self.positionInTextLine
self.text = chordName
self.font = self.font.fontWithSize(14)
self.textAlignment = NSTextAlignment.Center
self.userInteractionEnabled = true
}
required init?(coder aDecoder: NSCoder) { …Run Code Online (Sandbox Code Playgroud)