https://github.com/ahmetkgunay/collageview
Easy to use and fully customizable CollageView with multiple images inside.
https://github.com/ahmetkgunay/collageview
collage collageview images swift4
Last synced: 12 months ago
JSON representation
Easy to use and fully customizable CollageView with multiple images inside.
- Host: GitHub
- URL: https://github.com/ahmetkgunay/collageview
- Owner: ahmetkgunay
- License: mit
- Created: 2017-07-24T18:11:10.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-06-30T07:50:55.000Z (almost 5 years ago)
- Last Synced: 2025-04-23T22:43:36.488Z (about 1 year ago)
- Topics: collage, collageview, images, swift4
- Language: Swift
- Size: 16 MB
- Stars: 20
- Watchers: 2
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CollageView
[](http://cocoapods.org/pods/CollageView)
[](http://cocoapods.org/pods/CollageView)
[](http://cocoapods.org/pods/CollageView)
Custom View, collageView implementation with pure swift4.
This Library's aim is to make easily photo collage views.

## Usage
Like any other customViews, can be used with changing your view's class name as "CollageView" or initialize in code.
- Interface Builder
```swift
class ViewController: UIViewController {
//Assume that you have images array, or you can fetch from remote
let images = [#imageLiteral(resourceName: "amsterdam"), #imageLiteral(resourceName: "istanbul"), #imageLiteral(resourceName: "camera"), #imageLiteral(resourceName: "istanbul2"), #imageLiteral(resourceName: "mirror")];
@IBOutlet weak var collageView: CollageView!
override func viewDidLoad() {
super.viewDidLoad()
// Set delegate to trigger click events on imageview's
collageView.delegate = self
// Set datasource to fill your collageView with data
collageView.dataSource = self
}
deinit {
collageView.delegate = nil
collageView.dataSource = nil
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
- Initialize in Code
```swift
class ViewController: UIViewController {
//Assume that you have images array, or you can fetch from remote
let images = [#imageLiteral(resourceName: "amsterdam"), #imageLiteral(resourceName: "istanbul"), #imageLiteral(resourceName: "camera"), #imageLiteral(resourceName: "istanbul2"), #imageLiteral(resourceName: "mirror")];
var collageView = CollageView(frame: .zero)
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(collageView)
// Set delegate to trigger click events on imageview's
collageView.delegate = self
// Set datasource to fill your collageView with data
collageView.dataSource = self
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// Example frame
collageView.frame = view.bounds
}
deinit {
collageView.delegate = nil
collageView.dataSource = nil
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
```
After that, fill required dataSource and optional delegate methods
```swift
extension ViewController: CollageViewDataSource {
func collageViewNumberOfTotalItem(_ collageView: CollageView) -> Int {
// total images count to show up
return images.count
}
func collageViewNumberOfRowOrColoumn(_ collageView: CollageView) -> Int {
// Sets number of total coloumn or row count of layout direction
return 3
}
func collageViewLayoutDirection(_ collageView: CollageView) -> CollageViewLayoutDirection {
// Sets the starting layout to fill images with
// can be horizontol or vertical
// if set to horizontal, first image rowIndex is (0, 0) and second one is (1, 0)
// if set to vertical, first image rowIndex is (0, 0) and second one is (0, 1)
return .horizontal
}
func collageView(_ collageView: CollageView, configure itemView: CollageItemImageView, at index: Int) {
// MAGIC is in this code block
// You can prepare your item here also,
// You can fetch Images from Remote here!,
// Customize UI for item, and etc..
itemView.image = images[index]
itemView.layer.borderWidth = 3
}
}
extension ViewController: CollageViewDelegate {
func collageView(_ collageView: CollageView, didSelect itemView: CollageItemImageView, at index: Int) {
// Trigger click event of each image item
let message = "didSelect at index: \(index), rowIndex: \(String(describing: itemView.collageItem!.rowIndex))"
print(message)
}
}
```
## Demo App Output
## Installation
There are two ways to use CollageView in your project:
- using CocoaPods
- by cloning the project into your repository
### Installation with CocoaPods
[CocoaPods](http://cocoapods.org/) is a dependency manager for Swift and Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the [Get Started](http://cocoapods.org/#get_started) section for more details.
#### Podfile
```ruby
use_frameworks!
pod 'CollageView', '~> 1.0.4'
```
## Author
Ahmet Kazım Günay, ahmetkgunay@gmail.com
## License
CollageView is available under the MIT license. See the LICENSE file for more info.