Creating a Image Slider with Swift UIKit

Ozan Çiçek
2 min readMar 14, 2024

--

Hello everyone, today I will talk about how you can create a sliding image presentation with UIKit. We will use the free Pod Library provided by Trendyol (‘TYImageSlider’).

The process we will undertake is very simple. Firstly, we will install the library. After installing our library, let’s import it into our class.

pod 'TYImageSlider'

Then, we will create a UIView and define its class as ‘ImageSliderView’ from the library. Don’t forget to provide constraints while creating the UIView.

Afterwards, we add the created view to our class by dragging it.

After creating our view, we will then create the ImageSliderViewPresenter in our code, which will come from our library. The ImageSliderViewPresenter takes three parameters: the list of image URLs (imageUrls), whether looping will be enabled (loopingEnabled), and finally, the ‘view’ parameter where we will provide the UIView we created.

 
let imageSliderPresenter = ImageSliderViewPresenter(
imageUrls: imageUrls,
loopingEnabled: true,
view: imageSliderView)

Finally, we will assign the ‘presenter’ within the UIView we created to the ‘ImageSliderViewPresenter’ we added to our code.

imageSliderView.presenter = imageSliderPresenter

You can see a clearer example of code usage in the following example:

After completing all of these steps, we will have obtained a slider within the UIView we created, where we can slide images as shown in the video above.

We hope this article was helpful. If you have any questions or suggestions, please feel free to leave a comment.

Goodbye!
Contact: info@ozancicek.dev

--

--

Ozan Çiçek
Ozan Çiçek

Written by Ozan Çiçek

iOS Developer, Student #swift #uikit #apple #iOS #swiftui

No responses yet