這是可能的使用UIScrollView
分頁。
創建UIScrollView
,它作爲一個子視圖添加到您的UITableViewCell
(還應加上尺寸限制,使滾動視圖大小相同,因爲它的父範圍)
現在設置了滾動型驗證碼:
//set scroll view
scrollview.delegate = self;
scrollview.pagingEnabled = true;
scrollview.showsHorizontalScrollIndicator = false;
scrollview.showsVerticalScrollIndicator = false;
scrollview.contentSize.width = scrollview.bounds.width * 2.0;
//create delete swipe view
let deleteButton = UIView(frame: CGRectMake(scrollview.bounds.width,0,scrollview.bounds.width * 2.0,scrollview.bounds.height))
deleteButton.backgroundColor = UIColor.redColor()
let deleteLabel = UILabel(frame: CGRectMake(0,0,scrollview.bounds.width * 0.3,scrollview.bounds.height))
deleteLabel.textColor = UIColor.whiteColor()
deleteLabel.text = "Delete"
deleteLabel.contentMode = .Center
deleteLabel.textAlignment = .Center
deleteButton.addSubview(deleteLabel)
scrollview.addSubview(deleteButton)
現在委託函數:
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
if scrollView.contentOffset.x == 0{
return;
}
let confirmDelete = UIAlertController(title: "Are you sure you want to delete?", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
confirmDelete.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Destructive, handler: { (_) -> Void in
//Delete confirmed
}))
confirmDelete.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (_) -> Void in
scrollView.contentOffset.x = 0;
}))
rootViewController.presentViewController(confirmDelete, animated: true, completion: nil);
}
這將創造下一個效果:
如何在單元格中添加其他內容? –