[英]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.