简体   繁体   中英

show a tableView as pop up (with out covering the whole Screen)

What I'm trying to achieve is right here in this library but the only problem is that this library is not good if the amount of data that I want to show is big

What I have right now :

在此输入图像描述

as you can see , it is a ViewController which contains row and appears as a popup without covering whole screen

but when the data of rows is lengthy then I can't expand the hight of rows , thats why my data truncates say that in my first row's label text is : apple and in my second row's label text is : The banana is an edible fruit, botanically a berry, produced by several kinds of large herbaceous flowering plants in the genus Musa. in this case the second row will truncate the text (and thats my problem)

How can I get this multilines (expand row height)? do I have to create something by my own or we already have any library for this ?? or I have some other alternatives please let me know

This is what I want looks like :

在此输入图像描述

One of my prev. project I've implemented the way you need it. Rather than using any library we can implement like above.

Step 1 : Make view controller with xib as per requirement. Like this

在此输入图像描述

Step 2 : Create custom cell which we need in custom alert. In that create one label, Make sure that number of lines selected zero for that label and give top, bottom, left and right constraints.

Step 3 : Now in your view controller write below code.

    //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
    }

In addition you can customize blurEffect and animations for showing the above view. I hope this will help you. It will look like this.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM