A powerful and flexible SwiftUI component for creating interactive before/after comparison sliders. Perfect for showcasing image transformations, UI state changes, data visualizations, and any visual comparisons.
- π¨ Universal Content Support - Works with any SwiftUI View, not just images
- πΌοΈ Multiple Content Types - Images, custom views, charts, UI states, and more
- π RTL Language Support - Automatic right-to-left language adaptation
- π± Intuitive Interactions - Drag the slider or tap anywhere to compare
- β¨ Smooth Animations - Natural spring animations and transitions
- π― Modern SwiftUI - Built for iOS 17+ with latest SwiftUI features
- π Responsive Design - Adapts to any screen size and orientation
- π§© Simple API - Clean ViewBuilder syntax for easy integration
- File β Add Package Dependencies
- Enter URL:
https://github.com/mkhasson97/MoSlider.git - Add Package
dependencies: [
.package(url: "https://github.com/mkhasson97/MoSlider.git", from: "1.0.0")
]import SwiftUI
import MoSlider
struct ContentView: View {
var body: some View {
BeforeAfterSlider {
// Before content
Rectangle()
.fill(.red.gradient)
.overlay(Text("BEFORE").foregroundColor(.white))
} afterContent: {
// After content
Rectangle()
.fill(.blue.gradient)
.overlay(Text("AFTER").foregroundColor(.white))
}
.frame(height: 300)
.clipShape(RoundedRectangle(cornerRadius: 12))
}
}BeforeAfterSlider {
Image("before_photo")
.resizable()
.aspectRatio(contentMode: .fill)
} afterContent: {
Image("after_photo")
.resizable()
.aspectRatio(contentMode: .fill)
}
.frame(height: 400)BeforeAfterSlider {
// Loading state
VStack {
ProgressView()
.scaleEffect(2)
Text("Loading...")
.font(.title2)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.gray.opacity(0.3))
} afterContent: {
// Loaded state
VStack {
Image(systemName: "checkmark.circle.fill")
.font(.system(size: 80))
.foregroundColor(.green)
Text("Complete!")
.font(.title2)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.green.opacity(0.2))
}BeforeAfterSlider {
BarChart(data: oldData, color: .red)
} afterContent: {
BarChart(data: newData, color: .green)
}BeforeAfterSlider {
Image(systemName: "photo")
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(.secondary)
} afterContent: {
Image(systemName: "photo.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(.primary)
}
.frame(height: 200)BeforeAfterSlider {
AppPreview()
.preferredColorScheme(.light)
} afterContent: {
AppPreview()
.preferredColorScheme(.dark)
}BeforeAfterSlider {
LoadingSpinner(slow: true)
.overlay(Text("Slow").foregroundColor(.red))
} afterContent: {
LoadingSpinner(fast: true)
.overlay(Text("Fast").foregroundColor(.green))
}BeforeAfterSlider {
ListView(items: items)
} afterContent: {
GridView(items: items)
}The slider automatically adapts to your content and provides:
- Automatic RTL Support - Works seamlessly with right-to-left languages
- Responsive Labels - "Original" and "Processed" labels that fade based on position
- Smooth Interactions - Natural drag gestures and tap-to-position
- Flexible Sizing - Adapts to any frame size you provide
- iOS 17.0+
- macOS 14.0+
- Swift 5.9+
- Xcode 15.0+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 Mohammad Alhasson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Mohammad Alhasson
- Website: mkhasson97.com
- GitHub: @mkhasson97
- X: @mkhasson97
- Built with β€οΈ using SwiftUI
- Inspired by the need for flexible comparison tools in iOS development
- Thanks to the SwiftUI community for feedback and inspiration
If you're using MoSlider in your project, I'd love to hear about it! Feel free to:
- β Star this repository
- π Report issues
- π‘ Suggest new features
- π’ Share your implementations
Made with β€οΈ in Swift




