I have worked on titanium in past and it was very simple to use the paging control there. Just begun Xamarin iOS development and got stuck with this paging control. Not sure how to use it. I found an example here. It worked fine. My question is ,is the UIPageControl Useless ? I read it here that it is so. Does Xamarin have any control which could work like Titanium's Scrollable View ? Please suggest any better method than the code below .
Here's the code
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
createAndAddViewsToPagerControl ();
}
void createAndAddViewsToPagerControl ()
{
try {
int pageCount = PagerControlMain.Pages;
Console.WriteLine ("Pages Count in Page Control" + pageCount);
List<UIColor> _colList = new List<UIColor> {
UIColor.Red,
UIColor.Green,
UIColor.Blue,
UIColor.Yellow
};
int i = 0;
for (i = 0; i < pageCount; i++) {
UILabel label = new UILabel ();
RectangleF rectangle = new RectangleF ();
rectangle.X = (this.PagerScrollView.Frame.Width * i) + 50;
rectangle.Y = 0;
rectangle.Size = this.PagerScrollView.Frame.Size;
label.Frame = rectangle;
label.Text = i.ToString ();
label.TextColor = _colList [i];
this.PagerScrollView.AddSubview (label);
}
this.PagerControlMain.Pages = pageCount;
PagerScrollView.BackgroundColor = UIColor.Gray;
PagerScrollView.ContentSize = new SizeF (PagerScrollView.Frame.Width * i, PagerScrollView.Frame.Height);
this.PagerScrollView.Scrolled += ScrolledEvent;
} catch (Exception ex) {
Console.WriteLine ("Exception in PagerControl : " + ex);
}
}
private void ScrolledEvent (object sender, EventArgs e)
{
this.PagerControlMain.CurrentPage =
(int)System.Math.Floor (this.PagerScrollView.ContentOffset.X
/ this.PagerScrollView.Frame.Size.Width);
Console.WriteLine ("Scroll Event Fired");
}
partial void PagerControlMain_ValueChanged (UIPageControl sender)
{
Console.WriteLine ("Current Page " + sender.CurrentPage);
//throw new NotImplementedException ();
}