We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create Carousel sample in Xamarin.Forms.iOS platform

Platform: Xamarin.Forms |
Control: SfCarousel |
Published Date: February 24, 2017 |
Last Revised Date: June 24, 2019

       Carousel control allows navigating through image data in an interactive way so that they can be viewed or selected. Also, provides various customization options for its item arrangements. We can get the view of Carousel from any one of the following ways,

  1. Using CarouselItem
  2. Using ItemTemplate

 

     The below steps illustrate how to create the carousel control in Xamarin.Forms iOS platforms.

 

      Step 1: For getting the carousel control, need to add the following assemblies in your Xamarin.Forms project.

 

Project

Assemblies required

PCL

pcl\Syncfusion.SfCarousel.XForms.dll

 

iOS (Unified)

 

iOS-unified\Syncfusion.SfCarousel.iOS.dll
iOSunified\Syncfusion.SfCarousel.XForms.iOS.dll
iOS-unified\Syncfusion.SfCarousel.XForms.dll

 

 

      Step 2:  For getting the view of carousel control in iOS, need to add the SfCarouselRenderer() in AppDelegate class.

    C#

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
 
new SfCarouselRenderer();
 
LoadApplication(new App());
 
return base.FinishedLaunching(app, options);
}

 

      Create a carousel control using CarouselItem

     C#

public partial class KBSolutionPage : ContentPage
{
public KBSolutionPage()
{
    InitializeComponent();
 
    SfCarousel sfCarousel = new SfCarousel();
 
    sfCarousel.ItemWidth = 170;
    sfCarousel.ItemHeight = 250;
 
    ObservableCollection<SfCarouselItem> collectionOfItems = new ObservableCollection<SfCarouselItem>();
 
    collectionOfItems.Add(new SfCarouselItem() { ImageName = "images1.png" });
    collectionOfItems.Add(new SfCarouselItem() { ImageName = "images2.png" });
    collectionOfItems.Add(new SfCarouselItem() { ImageName = "images3.png" });
    collectionOfItems.Add(new SfCarouselItem() { ImageName = "images4.png" });
    collectionOfItems.Add(new SfCarouselItem() { ImageName = "images5.png" });
    collectionOfItems.Add(new SfCarouselItem() { ImageName = "images6.png" });
 
    sfCarousel.DataSource = collectionOfItems;
 
    this.Content = sfCarousel;
}
}
 

 

    Create a carousel control using ItemTemplate

    C#

public partial class KBSolutionPage : ContentPage
{
public KBSolutionPage()
{
    InitializeComponent();
 
    SfCarousel sfCarousel = new SfCarousel();
 
    sfCarousel.ItemWidth = 170;
    sfCarousel.ItemHeight = 250;
 
    var carouselModel = new List<CarouselModel> {
    new CarouselModel ("image1.png"),
    new CarouselModel ("image2.png"),
    new CarouselModel ("image3.png"),
    new CarouselModel ("image4.png"),
    new CarouselModel ("image5.png")
};
    var carouselModelDataTemplate = new DataTemplate(() =>
    {
        var grid = new Grid();
        var nameLabel = new Image();
        nameLabel.SetBinding(Image.SourceProperty, "Image");
        grid.Children.Add(nameLabel);
        return grid;
    });
 
    sfCarousel.ItemTemplate = carouselModelDataTemplate;
    sfCarousel.DataSource = carouselModel;
 
    this.Content = sfCarousel;
}
}
 
public class CarouselModel
{
public CarouselModel(string imagestr)
{
    Image = imagestr;
}
private string _image;
 
public string Image
{
    get { return _image; }
    set { _image = value; }
}
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Carousel

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon