If you do not want to add extra dependency, just copy Sources folder into your project.
Usage
Shimmering Animation
Conform any view to ShimmeringViewProtocol which identifies that shimmering animation will be applied to it or specified subviews. Define which subviews are animated in shimmeringAnimatedItems.
final class SampleTableViewCell: UITableViewCell, ShimmeringViewProtocol {
@IBOutlet weak var profileImageBackgroundView: UIView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var actionButton: UIButton!
@IBOutlet weak var secondLabel: UILabel!
@IBOutlet weak var secondActionButton: UIButton!
var shimmeringAnimatedItems: [UIView] {
[
profileImageBackgroundView,
nameLabel,
actionButton,
secondLabel,
secondActionButton
]
}
}
Or alternatively you can define that a type of view will be animated just extending ShimmeringViewProtocol
Then call setShimmeringAnimationWithSubviews(template:superviewBackgroundColor:) extension of UIView for any view (basically a superview). This function finds all descendand subviews to be set as template and applies animation. Before the call, make sure the view is loaded.
For UITableViewCell, to mark as template, view you call on willDisplay delegate.
You can hide, for example after a completion of a task, with template = false parameter. It is not needed to give superviewBackgroundColor value when hiding template (with shimmering) animation.
cell.setTemplateWithSubviews(template: false)
Light Theme
Dark Theme
Excluded Views
You can set excludedItems with ShimmeringViewProtocol to set views will be excluded while setting animation.
var excludedItems: Set<UIView> {
[nameLabel]
}
Placeholder
You can only set template view without shimmering animation via setting animation: false. (like .redacted(reason: .placeholder) in SwiftUI)
Template view (and also Shimmering effect) frames are calculated based on their intrinsicContentSize or their layout constraints. So you should set dummy values for UILabels, UITextView etc. or set their constraints to visually draw their templates.
Example
The exmple project demonstrates how to use it. Pull the repo and check ShimmerExamples.
Contributing
Contributions are welcome 🙌
License
UIView-Shimmer is available under the MIT license. See the LICENSE file for more info.
Super easy way to apply shimmering effect to any view and its subviews for iOS applications.
Requirements
Installation
CocoaPods
UIView-Shimmer
is available through CocoaPods. To install it, simply add the following line to your Podfile:Then import
Swift Package Manager
UIView-Shimmer
is available through Swift Package Manager.To add package go to
File -> Swift Packages -> Add Package Dependancy
Manuel
If you do not want to add extra dependency, just copy Sources folder into your project.
Usage
Shimmering Animation
Conform any view to
ShimmeringViewProtocol
which identifies that shimmering animation will be applied to it or specified subviews. Define which subviews are animated inshimmeringAnimatedItems
.Or alternatively you can define that a type of view will be animated just extending
ShimmeringViewProtocol
Then call
setShimmeringAnimationWithSubviews(template:superviewBackgroundColor:)
extension ofUIView
for any view (basically a superview). This function finds all descendand subviews to be set as template and applies animation. Before the call, make sure the view is loaded.For UITableViewCell, to mark as template, view you call on
willDisplay
delegate.You can hide, for example after a completion of a task, with
template = false
parameter. It is not needed to givesuperviewBackgroundColor
value when hiding template (with shimmering) animation.Excluded Views
You can set
excludedItems
withShimmeringViewProtocol
to set views will be excluded while setting animation.Placeholder
You can only set template view without shimmering animation via setting
animation: false
. (like.redacted(reason: .placeholder)
in SwiftUI)Note
Template view (and also Shimmering effect) frames are calculated based on their
intrinsicContentSize
or their layout constraints. So you should set dummy values forUILabels
,UITextView
etc. or set their constraints to visually draw their templates.Example
The exmple project demonstrates how to use it. Pull the repo and check ShimmerExamples.
Contributing
Contributions are welcome 🙌
License
UIView-Shimmer is available under the MIT license. See the LICENSE file for more info.