Skip to content

Commit

Permalink
Merge pull request #16 from cruisediary/feature/add-pastel-label
Browse files Browse the repository at this point in the history
Add PastelLabel for Issue #11
  • Loading branch information
cruisediary authored Oct 4, 2017
2 parents 41fc8c3 + f1e73dc commit d0d8324
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 25 deletions.
70 changes: 70 additions & 0 deletions Pastel/Classes/PastelLabel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// PastelLabel.swift
// Pastel
//
// Created by Cruz on 21/05/2017.
//
//

import UIKit

public protocol PastelLabelable {
var text: String? { get set }
var font: UIFont? { get set }
var textAlignment: NSTextAlignment { get set }
var attributedText: NSAttributedString? { get set }
}

open class PastelLabel: PastelView, PastelLabelable {
private let label = UILabel()

// PastelLabelabel
open var text: String? {
didSet {
label.text = text
}
}

open var font: UIFont? {
didSet {
label.font = font
}
}

open var attributedText: NSAttributedString? {
didSet {
label.attributedText = attributedText
}
}

open var textAlignment: NSTextAlignment = .center {
didSet {
label.textAlignment = textAlignment
}
}

public override init(frame: CGRect) {
super.init(frame: frame)
setup()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}

open override func awakeFromNib() {
super.awakeFromNib()
setup()
}

func setup() {
textAlignment = .center
mask = label
}

open override func layoutSubviews() {
super.layoutSubviews()
label.frame = bounds
}
}
34 changes: 34 additions & 0 deletions Pastel/Classes/PastelPoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// PastelPoint.swift
// Pastel
//
// Created by Cruz on 21/05/2017.
//
//

import UIKit

@objc
public enum PastelPoint: Int {
case left
case top
case right
case bottom
case topLeft
case topRight
case bottomLeft
case bottomRight

var point: CGPoint {
switch self {
case .left: return CGPoint(x: 0.0, y: 0.5)
case .top: return CGPoint(x: 0.5, y: 0.0)
case .right: return CGPoint(x: 1.0, y: 0.5)
case .bottom: return CGPoint(x: 0.5, y: 1.0)
case .topLeft: return CGPoint(x: 0.0, y: 0.0)
case .topRight: return CGPoint(x: 1.0, y: 0.0)
case .bottomLeft: return CGPoint(x: 0.0, y: 1.0)
case .bottomRight: return CGPoint(x: 1.0, y: 1.0)
}
}
}
25 changes: 0 additions & 25 deletions Pastel/Classes/PastelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,6 @@ open class PastelView: UIView {
static let key = "ColorChange"
}

@objc
public enum PastelPoint: Int {
case left
case top
case right
case bottom
case topLeft
case topRight
case bottomLeft
case bottomRight

var point: CGPoint {
switch self {
case .left: return CGPoint(x: 0.0, y: 0.5)
case .top: return CGPoint(x: 0.5, y: 0.0)
case .right: return CGPoint(x: 1.0, y: 0.5)
case .bottom: return CGPoint(x: 0.5, y: 1.0)
case .topLeft: return CGPoint(x: 0.0, y: 0.0)
case .topRight: return CGPoint(x: 1.0, y: 0.0)
case .bottomLeft: return CGPoint(x: 0.0, y: 1.0)
case .bottomRight: return CGPoint(x: 1.0, y: 1.0)
}
}
}

// Custom Direction
open var startPoint: CGPoint = PastelPoint.topRight.point
open var endPoint: CGPoint = PastelPoint.bottomLeft.point
Expand Down

0 comments on commit d0d8324

Please sign in to comment.