Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cardoso/mmuikitextensions
Useful UIKit extensions
https://github.com/cardoso/mmuikitextensions
ios swift swift3 uikit
Last synced: about 9 hours ago
JSON representation
Useful UIKit extensions
- Host: GitHub
- URL: https://github.com/cardoso/mmuikitextensions
- Owner: cardoso
- Created: 2016-12-06T21:06:21.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-15T21:29:45.000Z (almost 8 years ago)
- Last Synced: 2024-11-01T21:02:23.096Z (4 days ago)
- Topics: ios, swift, swift3, uikit
- Size: 84 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MMUIKitExtensions
>Useful UIKit extensions## How to Use
>This is intended to be a collection of snippets rather than a monolithic package, so just copy and paste the extension you need in a file somewhere in your project## UILabel with Ghost Animation
### Preview
![UILabelGhost](https://github.com/matheusmcardoso/MMUIKitExtensions/raw/master/media/label-00-ghost.gif)
### Usage
```swift
@IBAction func pressedUp(_ sender: UIButton) {
currentValue += 100
numberLabel.doGhostAnimation(text: "+100", color: UIColor.green, tX: numberLabel.center.x/3, tY: -50, sX: 0.5, sY: 0.5)
}@IBAction func pressedDown(_ sender: UIButton) {
currentValue -= 100
numberLabel.doGhostAnimation(text: "-100", color: UIColor.red, tX: numberLabel.center.x/3, tY: 100, sX: 0.5, sY: 0.5)
}
```### Extension
```swift
// UILabel+Ghost.swift
// UILabel with Ghost Animation
// https://github.com/matheusmcardoso/MMUIKitExtensionsimport UIKit
extension UILabel {
func doGhostAnimation(text: String? = nil, color: UIColor = UIColor.green,
tX: CGFloat = 0, tY: CGFloat = -50, sX: CGFloat = 0.5, sY: CGFloat = 0.5,
duration: TimeInterval = 0.5, completion: ((Bool) -> Void)? = nil) {let oldSize = self.frame.size
var size = self.frame.sizelet oldColor = self.textColor
self.textColor = colorlet oldText = self.text
if let text = text {
self.text = text
size = self.text!.size(attributes: [NSFontAttributeName: self.font!])
self.frame.size = size
}
self.superview!.layoutIfNeeded()guard let view = self.snapshotView(afterScreenUpdates: true) else { return }
self.textColor = oldColor
self.text = oldText
self.frame.size = oldSizeself.addSubview(view)
UIView.animate(withDuration: duration, animations: {
view.alpha = 0
view.frame = view.frame.applying(CGAffineTransform(translationX: tX, y: tY)).applying(CGAffineTransform(scaleX: sX, y: sY))
}, completion: {
completed in
view.removeFromSuperview()
completion?(completed)
})
}
}```