Articles in this section
Category / Section

How to update Images dynamically for a particular item in SfRotator

1 min read

Update images dynamically for a particular item in SfRotator:

 

Step 1: Add items to rotator using SfRotatorItem.

Step 2: Add a specific image to a particular item, and reload the view using ReloadInputViews.

 

The following code demonstrates how to update images dynamically for a particular item in SfRotator.

 

namespace RotatorTestApp
{
    public partial class ViewController : UIViewController
    {
        SfRotator rotator;
        NSMutableArray collection;
        UILabel indexLabel;
        UIButton addButton;
        SfRotatorItem item1, item2, item3, item4, item5;
        UIImageView imageView1, imageView2, imageView3, imageView4, imageView5;
        public ViewController (IntPtr handle) : base (handle)
        {
        }
        public override void ViewDidLoad ()
        {
          base.ViewDidLoad ();
            collection = new NSMutableArray();
            indexLabel = new UILabel();
            indexLabel.Frame = new CGRect(10,340,this.View.Frame.Width,40);
            addButton = new UIButton();
            addButton.BackgroundColor = UIColor.Red;
            addButton.Frame = new CGRect(10,380,this.View.Frame.Width,40);
            addButton.SetTitle("Add Photo", UIControlState.Normal);
            addButton.TouchDown += AddButton_TouchDown;
 
            rotator = new SfRotator();
            rotator.Frame = new CGRect(0,10,this.View.Frame.Width,300);
            indexLabel.Text = "Rotator SelectedIndex is: 0";
            
            item1 = new SfRotatorItem();
            imageView1 = new UIImageView();
            imageView1.Frame = rotator.Frame;
            imageView1.Image = new UIImage("movie0.png");
            item1.View = imageView1;
            collection.Add(item1);
 
            item2 = new SfRotatorItem();
            imageView2 = new UIImageView();
            imageView2.Frame = rotator.Frame;
            imageView2.Image = new UIImage("movie1.png");
            item2.View = imageView2;
            collection.Add(item2);
 
            item3 = new SfRotatorItem();
            imageView3 = new UIImageView();
            imageView3.Frame = rotator.Frame;
            imageView3.Image = new UIImage("movie2.png");
            item3.View = imageView3;
            collection.Add(item3);
 
            item4 = new SfRotatorItem();
            imageView4 = new UIImageView();
            imageView4.Frame = rotator.Frame;
            imageView4.Image = new UIImage("movie3.png");
            item4.View = imageView4;
            collection.Add(item4);
 
            item5 = new SfRotatorItem();
            imageView5 = new UIImageView();
            imageView5.Frame = rotator.Frame;
            imageView5.Image = new UIImage("movie4.png");
            item5.View = imageView5;
            collection.Add(item5);
            rotator.DataSource = collection;
            rotator.SelectionChanged += Rotator_SelectionChanged;
            this.Add(rotator);
            this.Add(indexLabel);
            this.Add(addButton);
          }
        private void AddButton_TouchDown(object sender, EventArgs e)
        {
            imageView1.Image = new UIImage("movie3.png");
            imageView1.ReloadInputViews();
        }
        private void Rotator_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            indexLabel.Text = "Rotator SelectedIndex is: " + rotator.SelectedIndex;
            //e.Index also can be used
        }
    }
}

 

 

 

 

Before updating the image:

 

 

After updating the image:

 

Please find the sample from the below link:

http://www.syncfusion.com/downloads/support/forum/139462/ze/RotatorTestApp134243109

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied