public override void ViewDidLoad() { base.ViewDidLoad(); this.Photos = new TKDataSource("PhotosWithNames", "json", "photos"); this.Names = new TKDataSource("PhotosWithNames", "json", "names"); this.Photos.Settings.ListView.CreateCell(delegate(TKListView listView, NSIndexPath indexPath, NSObject item) { TKListViewCell cell = listView.DequeueReusableCell("simpleCell", indexPath) as TKListViewCell; return(cell); }); this.Photos.Settings.ListView.InitCell(delegate(TKListView listView, NSIndexPath indexPath, TKListViewCell cell, NSObject item) { NSString imageName = (NSString)this.Photos.Items [indexPath.Row]; cell.ImageView.Image = new UIImage(imageName); cell.TextLabel.Text = this.Names.Items [indexPath.Row] as NSString; TKView view = (TKView)cell.BackgroundView; view.Stroke.StrokeSides = listView.Layout.IsKindOfClass(new Class(typeof(TKListViewColumnsLayout))) ? TKRectSide.Right | TKRectSide.Bottom : TKRectSide.All; view.SetNeedsDisplay(); }); this.ListView = new TKListView(this.View.Bounds); this.ListView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; this.ListView.WeakDataSource = this.Photos; this.ListView.RegisterClassForCell(new Class(typeof(SimpleListViewCell)), "simpleCell"); this.View.AddSubview(this.ListView); this.WrapLayoutSelected(this, EventArgs.Empty); }
public override TKListViewCell CellForItem(TKListView listView, NSIndexPath indexPath) { TKListViewCell cell = listView.DequeueReusableCell("cell", indexPath) as TKListViewCell; cell.TextLabel.Text = this.owner.sampleArrayOfStrings.GetItem <NSString> ((uint)indexPath.Row); return(cell); }
void AnimateButtonInCell(TKListViewCell cell, CGPoint offset) { if (offset.X > 0) { return; } UIButton bMore = cell.SwipeBackgroundView.Subviews [0] as UIButton; UIButton bFlag = cell.SwipeBackgroundView.Subviews [1] as UIButton; UIButton bTrash = cell.SwipeBackgroundView.Subviews [2] as UIButton; CGSize size = cell.Frame.Size; if (this.buttonAnimationEnabled) { float x = (float)size.Width - (float)Math.Abs(offset.X); float delta = (float)Math.Abs(offset.X) / (float)this.listView.CellSwipeLimits.Right; bTrash.Frame = new CGRect(x + 20 + 100 * delta, 0, 60, size.Height); bFlag.Frame = new CGRect(x + 10 + 50 * delta, 0, 60, size.Height); bMore.Frame = new CGRect(x, 0, 60, size.Height); } else { bMore.Frame = new CGRect(size.Width - 180, 0, 60, size.Height); bFlag.Frame = new CGRect(size.Width - 120, 0, 60, size.Height); bTrash.Frame = new CGRect(size.Width - 60, 0, 60, size.Height); } }
public override void DidReorderItemFromIndexPath(TKListView listView, NSIndexPath originalIndexPath, NSIndexPath targetIndexPath) { TKListViewCell cell = listView.CellForItem(originalIndexPath); cell.BackgroundView.BackgroundColor = UIColor.White; this.owner.dataSource.DidReorderItemFromTo(listView, originalIndexPath, targetIndexPath); }
public override TKListViewCell CellForItem(TKListView listView, NSIndexPath indexPath) { TKListViewCell cell = (TKListViewCell)listView.DequeueReusableCell("cell", indexPath); NSString imageName = (NSString)this.owner.Photos.Items [indexPath.Row]; cell.ImageView.Image = UIImage.FromBundle(imageName); cell.TextLabel.Text = (NSString)this.owner.Names.Items [indexPath.Row]; return(cell); }
public override void DidHighlightItemAtIndexPath(TKListView listView, NSIndexPath indexPath) { Console.WriteLine("Did highlight item at row {0}", this.owner.dataSource.Items [indexPath.Row]); TKListViewCell cell = listView.CellForItem(indexPath); if (!cell.Selected && listView.SelectionBehavior == TKListViewSelectionBehavior.LongPress) { cell.SelectedBackgroundView.Hidden = true; } }
// >> listview-respond-cs public override void DidSelectItemAtIndexPath(TKListView listView, NSIndexPath indexPath) { this.owner.label.Text = string.Format("Selected: {0}", this.owner.dataSource.Items[indexPath.Row]); Console.WriteLine("Did select item at row {0}", this.owner.dataSource.Items [indexPath.Row]); TKListViewCell cell = listView.CellForItem(indexPath); if (cell != null) { cell.SelectedBackgroundView.Hidden = false; } }
public override TKListViewCell CellForItem(TKListView listView, NSIndexPath indexPath) { TKListViewCell cell = listView.DequeueReusableCell("cell", indexPath) as TKListViewCell; cell.BackgroundView.BackgroundColor = UIColor.FromWhiteAlpha(0.3f, 0.5f); string imageName = this.owner.photos.Items [indexPath.Row] as NSString; cell.ImageView.Image = new UIImage(imageName); cell.TextLabel.Text = this.owner.names.Items [indexPath.Row] as NSString; Random r = new Random(); cell.DetailTextLabel.Text = this.owner.loremIpsum.RandomString(10 + r.Next(0, 16), indexPath); cell.DetailTextLabel.TextColor = UIColor.White; ((TKView)cell.BackgroundView).Stroke = null; return(cell); }
public override TKListViewCell CellForItem(TKListView listView, NSIndexPath indexPath) { TKListViewCell cell = listView.DequeueReusableCell("cell", indexPath) as TKListViewCell; bool isUpdated = this.owner.IsUpdated(indexPath); cell.TextLabel.Text = this.owner.data [indexPath.Row]; cell.BackgroundView.BackgroundColor = isUpdated ? new UIColor(1f, 1f, 0f, 0.4f) : UIColor.White; if (isUpdated) { UIView.Animate(0.5f, () => { cell.BackgroundView.Alpha = 1; }); } return(cell); }
public override void ViewDidLoad() { this.AddOption("YES", "Animate buttons", EnableButtonAnimation); this.AddOption("NO", "Animate buttons", DisableButtonAnimation); base.ViewDidLoad(); buttonAnimationEnabled = true; NSMutableDictionary mails = new NSMutableDictionary(); mails.Add(new NSString("Joyce Dean"), new NSString("Sales report for January")); mails.Add(new NSString("Joel Robertson"), new NSString("Planned network mainternance")); mails.Add(new NSString("Sherman Martin"), new NSString("IT help desk")); mails.Add(new NSString("Lela Richardson"), new NSString("Summaries of my interviews with customers")); mails.Add(new NSString("Jackie Maldonado"), new NSString("REMAINDER: corporate meeting")); mails.Add(new NSString("Kathryn Byrd"), new NSString("Stock options")); mails.Add(new NSString("Ervin Powers"), new NSString("Thank you!")); mails.Add(new NSString("Leland Warner"), new NSString("Meeting with Jack")); mails.Add(new NSString("Nicholas Bowers"), new NSString("Please share these articles")); mails.Add(new NSString("Alex Soto"), new NSString("Additional information for Jack")); mails.Add(new NSString("Naomi Carson"), new NSString("Miss you!")); mails.Add(new NSString("Lela Richardson"), new NSString("Summaries of my interviews with customers")); mails.Add(new NSString("Rufus Edwards"), new NSString("Training")); mails.Add(new NSString("Kathryn Byrd"), new NSString("Stock options")); mails.Add(new NSString("Ian Ellis"), new NSString("Do you like this blog article?")); mails.Add(new NSString("Pat Vasquez"), new NSString("The latest UI design")); mails.Add(new NSString("Chelsea Burton"), new NSString("Need this article!")); mails.Add(new NSString("Karl Bates"), new NSString("Training update")); mails.Add(new NSString("Evan Rivera"), new NSString("Safety instructions")); mails.Add(new NSString("Tony Lawson"), new NSString("Missed our converstation")); mails.Add(new NSString("Wallace Little"), new NSString("Swift is awessome")); mails.Add(new NSString("Carrie Tran"), new NSString("Missed conference call with Jack")); mails.Add(new NSString("Tyler Washington"), new NSString("HR question")); mails.Add(new NSString("Dominick Holloway"), new NSString("Wellcome!")); mails.Add(new NSString("Clark Sharp"), new NSString("Important question!")); this.dataSource.ItemSource = mails; this.dataSource.Settings.ListView.CreateCell(delegate(TKListView listView, NSIndexPath indexPath, NSObject item) { TKListViewCell cell = listView.DequeueReusableCell("defaultCell", indexPath) as TKListViewCell; // >> listview-swipe-view-cs if (cell.SwipeBackgroundView.Subviews.Length == 0) { CGSize size = cell.Frame.Size; UIFont font = UIFont.SystemFontOfSize(14); UIButton bMore = new UIButton(new CGRect(size.Width - 180, 0, 60, size.Height)); bMore.SetTitle("More", UIControlState.Normal); bMore.BackgroundColor = UIColor.LightGray; bMore.TitleLabel.Font = font; bMore.AddTarget(ButtonTouched, UIControlEvent.TouchUpInside); cell.SwipeBackgroundView.AddSubview(bMore); UIButton bFlag = new UIButton(new CGRect(size.Width - 120, 0, 60, size.Height)); bFlag.SetTitle("Flag", UIControlState.Normal); bFlag.BackgroundColor = UIColor.Orange; bFlag.TitleLabel.Font = font; bFlag.AddTarget(ButtonTouched, UIControlEvent.TouchUpInside); cell.SwipeBackgroundView.AddSubview(bFlag); UIButton bTrash = new UIButton(new CGRect(size.Width - 60, 0, 60, size.Height)); bTrash.SetTitle("Trash", UIControlState.Normal); bTrash.BackgroundColor = UIColor.Red; bTrash.TitleLabel.Font = font; bTrash.AddTarget(ButtonTouched, UIControlEvent.TouchUpInside); cell.SwipeBackgroundView.AddSubview(bTrash); UIButton bUnread = new UIButton(new CGRect(0, 0, 60, size.Height)); bUnread.SetTitle("Mark as Unread", UIControlState.Normal); bUnread.BackgroundColor = UIColor.Blue; bUnread.TitleLabel.Font = font; bUnread.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap; bUnread.TitleLabel.TextAlignment = UITextAlignment.Center; bUnread.AddTarget(ButtonTouched, UIControlEvent.TouchUpInside); cell.SwipeBackgroundView.AddSubview(bUnread); } // << listview-swipe-view-cs return(cell); }); this.dataSource.Settings.ListView.InitCell(delegate(TKListView listView, NSIndexPath indexPath, TKListViewCell cell, NSObject item) { cell.TextLabel.Text = item as NSString; NSDictionary dict = this.dataSource.ItemSource as NSDictionary; cell.DetailTextLabel.AttributedText = this.AttributedMailText(dict[item] as NSString); cell.ContentInsets = new UIEdgeInsets(5, 10, 5, 10); }); this.listViewDelegate = new ListViewDelegate(this); this.listView.Frame = this.View.Bounds; this.listView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; this.listView.WeakDataSource = this.dataSource; this.listView.Delegate = this.listViewDelegate; // >> listview-swipe-cs this.listView.AllowsCellSwipe = true; // << listview-swipe-cs // >> listview-swipe-limits-cs this.listView.CellSwipeLimits = new UIEdgeInsets(0, 60, 0, 180); // << listview-swipe-limits-cs // >> listview-swipe-treshold-cs this.listView.CellSwipeTreshold = 30; // << listview-swipe-treshold-cs this.View.AddSubview(this.listView); TKListViewLinearLayout layout = (TKListViewLinearLayout)this.listView.Layout; layout.ItemSize = new CGSize(100, 80); }
public override void WillReorderItemAtIndexPath(TKListView listView, NSIndexPath indexPath) { TKListViewCell cell = listView.CellForItem(indexPath); cell.BackgroundView.BackgroundColor = UIColor.Yellow; }
void AnimateButtonInCell(TKListViewCell cell, CGPoint offset) { if (offset.X > 0) { return; } UIButton bMore = cell.SwipeBackgroundView.Subviews [0] as UIButton; UIButton bFlag = cell.SwipeBackgroundView.Subviews [1] as UIButton; UIButton bTrash = cell.SwipeBackgroundView.Subviews [2] as UIButton; CGSize size = cell.Frame.Size; if (this.buttonAnimationEnabled) { float x = (float)size.Width - (float)Math.Abs (offset.X); float delta = (float)Math.Abs (offset.X) / (float)this.listView.CellSwipeLimits.Right; bTrash.Frame = new CGRect (x + 20 + 100 * delta, 0, 60, size.Height); bFlag.Frame = new CGRect (x + 10 + 50 * delta, 0, 60, size.Height); bMore.Frame = new CGRect (x, 0, 60, size.Height); } else { bMore.Frame = new CGRect (size.Width - 180, 0, 60, size.Height); bFlag.Frame = new CGRect (size.Width - 120, 0, 60, size.Height); bTrash.Frame = new CGRect (size.Width - 60, 0, 60, size.Height); } }
public override void DidFinishSwipeCell(TKListView listView, TKListViewCell cell, NSIndexPath indexPath, CGPoint offset) { Console.WriteLine ("Did swipe cell at index: {0}", indexPath.Row); }
public override void DidSwipeCell(TKListView listView, TKListViewCell cell, NSIndexPath indexPath, CGPoint offset) { this.owner.AnimateButtonInCell (cell, offset); }
public override void DidFinishSwipeCell(TKListView listView, TKListViewCell cell, NSIndexPath indexPath, CGPoint offset) { Console.WriteLine("Did swipe cell at index: {0}", indexPath.Row); }
public override void DidSwipeCell(TKListView listView, TKListViewCell cell, NSIndexPath indexPath, CGPoint offset) { this.owner.AnimateButtonInCell(cell, offset); }
public override void DidFinishSwipeCell (TKListView listView, TKListViewCell cell, NSIndexPath indexPath, CGPoint offset) { ListViewDelegate.lastIndex = indexPath.Row; ListViewDelegate.lastOne = (NSMutableDictionary) owner.dataSource.Items [indexPath.Row]; }