2016-08-06 68 views
1

我想實現的是在這裏this庫,但唯一的問題是,這個庫是不好,如果我想要的數據量展現的是大顯示一個tableview作爲彈出(與覆蓋整個屏幕)

我有什麼權利現在:

enter image description here

,你可以看到,這是一個視圖控制器包含行出現一個彈出沒有覆蓋整個屏幕

但是當行的數據是冗長的,我無法擴大行的高度,這就是爲什麼我的數據截斷 說,在我的第一行的標籤文本是:蘋果和在我的第二行的標籤文本是:香蕉是可食的水果,植物學上的一種漿果,由幾種大型草本開花植物在芭蕉屬中產生。在這種情況下,第二行將截斷文本(這就是我的問題)

我怎樣才能得到這個多行(擴大行高)?我是否必須自己創建一些東西,或者我們已經有這樣的庫?或者我有一些其他的替代品,請讓我知道

這就是我想要的樣子:

enter image description here

+0

嘿,你檢查了我的答案。 ? –

回答

0

我的一個分組的。項目我已經實現了你需要的方式。而不是使用我們可以像上面那樣實現的任何庫。

第1步:根據需要使用xib製作視圖控制器。像這樣

enter image description here

第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和動畫以顯示上述視圖。我希望這能幫到您。它看起來像這樣。

enter image description here

相關問題