-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from cruisediary/feature/add-pastel-label
Add PastelLabel for Issue #11
- Loading branch information
Showing
3 changed files
with
104 additions
and
25 deletions.
There are no files selected for viewing
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
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 | ||
} | ||
} |
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
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) | ||
} | ||
} | ||
} |
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