Skip to content

Commit

Permalink
Adding set extension to UILabelExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
vilapuigvila authored and Khalian committed Feb 5, 2017
1 parent c9b4622 commit 3814074
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Add subsequent changes that you make in this section.
9. **UIEdgeInsets**
- `init(inset: CGFloat)` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/368) by *furuyan*

10. **UILabel**
- `set(text _text: String?, duration: TimeInterval)` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/340) by *vilapuigvila*

## [Version 1.8]

### Fixed bugs
Expand Down
8 changes: 4 additions & 4 deletions EZSwiftExtensionsTests/UILabelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ class UILabelTests: XCTestCase {
XCTAssertEqual(label2.font.pointSize, 20)
}

func testText() {
func testSet() {

let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
label.setText("EZSwiftExtensions✅", animated: false, duration: nil)
label.set(text: "EZSwiftExtensions✅", duration: 1)
XCTAssertEqual(label.text, "EZSwiftExtensions✅")

label.text = ""
label.setText("EZSwiftExtensions🚀", animated: true, duration: 5)
label.set(text: "EZSwiftExtensions🚀", duration: 0)
XCTAssertEqual(label.text, "EZSwiftExtensions🚀")

label.text = ""
label.setText("EZSwiftExtensions❤️", animated: true, duration: nil)
label.set(text: "EZSwiftExtensions❤️", duration: 1)
XCTAssertEqual(label.text, "EZSwiftExtensions❤️")
}

Expand Down
17 changes: 6 additions & 11 deletions Sources/UILabelExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,11 @@ extension UILabel {
self.fitHeight()
sizeToFit()
}

/// EZSwiftExtensions
public func setText(_ text: String?, animated: Bool, duration: TimeInterval?) {
if animated {
UIView.transition(with: self, duration: duration ?? 0.3, options: .transitionCrossDissolve, animations: { () -> Void in
self.text = text
}, completion: nil)
} else {
self.text = text
}


/// EZSwiftExtensions (if duration set to 0 animate wont be)
public func set(text _text: String?, duration: TimeInterval) {
UIView.transition(with: self, duration: duration, options: .transitionCrossDissolve, animations: { () -> Void in
self.text = _text
}, completion: nil)
}
}

0 comments on commit 3814074

Please sign in to comment.