[英]show a tableView as pop up (with out covering the whole Screen)
我想要實現的是在這個庫中,但唯一的問題是,如果我想顯示的數據量很大,這個庫就不好了
我現在擁有的:
正如您所看到的,它是一個ViewController,它包含行並顯示為彈出窗口而不覆蓋整個屏幕
但是當行的數據很長時,我無法擴展行的高度,這就是為什么我的數據截斷說我的第一行的標簽文本是: apple和我的第二行的標簽文本是: 香蕉是可食用的水果,植物學上的一種漿果,由Musa屬的幾種大型草本開花植物產生。 在這種情況下,第二行將截斷文本(這就是我的問題)
如何獲得此多線(擴展行高)? 我必須自己創建一些東西,或者我們已經有了這個庫嗎? 或者我有其他選擇請告訴我
這就是我想要的樣子:
我的上一個。 項目我已經實現了你需要它的方式。 我們可以像上面那樣使用任何庫。
步驟1:根據需要使用xib創建視圖控制器。 像這樣
第2步:在自定義警報中創建我們需要的自定義單元格。 在創建一個標簽時,確保該標簽的行數為零,並給出頂部,底部,左側和右側約束。
第3步:現在在視圖控制器中編寫下面的代碼。
//MARK: Variable declaration
let suggestionsView = SuggestionsVC(nibName: "SuggestionsVC", bundle: nil)
var blurEffectView : UIVisualEffectView?
//MARK: Show custom view & remove custom view
@IBAction func showAlert(sender: AnyObject)
{
showSuggestionView()
}
func showSuggestionView()
{
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView!.userInteractionEnabled = true
blurEffectView!.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.removeSuggestionsView)))
if !UIAccessibilityIsReduceTransparencyEnabled()
{
self.view.backgroundColor = UIColor.clearColor()
blurEffectView!.frame = self.view.bounds
self.view.addSubview(blurEffectView!)
}
else
{
self.view.backgroundColor = UIColor.blackColor()
}
suggestionsView.view.frame = CGRectMake(30,0, self.view.frame.size.width - 30, 260
)
suggestionsView.view.center = CGPointMake((self.view.bounds.width)/2,(self.view.bounds.height)/2)
suggestionsView.cancelButton.addTarget(self, action: #selector(self.removeSuggestionsView), forControlEvents: UIControlEvents.TouchUpInside)
suggestionsView.confirmButton.addTarget(self, action: #selector(self.removeSuggestionsView), forControlEvents: UIControlEvents.TouchUpInside)
suggestionsView.listTableView.registerNib(UINib(nibName: "SampleTableViewCell", bundle: nil), forCellReuseIdentifier: "SampleTableViewCell")
suggestionsView.listTableView.estimatedRowHeight = 44.0
suggestionsView.listTableView.rowHeight = UITableViewAutomaticDimension
self.view.addSubview(suggestionsView.view)
suggestionsView.listTableView.dataSource = self
}
func removeSuggestionsView()
{
suggestionsView.view.removeFromSuperview()
blurEffectView!.removeFromSuperview()
self.view.backgroundColor = UIColor.lightGrayColor()
}
//MARK: TableView DataSource
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: SampleTableViewCell = (tableView.dequeueReusableCellWithIdentifier("SampleTableViewCell") as? SampleTableViewCell)!
if indexPath.row % 2 == 0
{
cell.sampleText.text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa."
}
else
{
cell.sampleText.text = "Lorem ipsum "
}
return cell
}
此外,您可以自定義blurEffect和動畫以顯示上述視圖。 我希望這能幫到您。 它看起來像這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.