2017-01-18 7 views
-1

私は、テーブルビューのセルにダイナミックラベルまたはイメージを作成したいと考えています。スクロールするとゆっくり実行されるため、サブビューをtableviewセルのコンテンツビューにループしたくないです。だから誰でも私を助けてくれる?この画像のように:tableviewcellでラベルや画像を動的にするには?

Like this image

私のコードです。 enter image description here

+1

上で動作します試した?投稿してください! – dfd

+0

https://i.stack.imgur.com/fjdUj.png –

+0

私はそれをやろうとしますが、滑らかではありません –

答えて

0

あなたのコードのコンテキストを知らなくても、このような何かが動作することができます:

NOTEこれはiOSの<あなたが持っているどのようなコード= 8

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { 
    @IBOutlet weak var TableVC: UITableView! 

    let elements = ["item1 item2 item3","item1 item2", "item1"] 



    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.TableVC.delegate = self 
     self.TableVC.dataSource = self 


     self.TableVC.register(UITableViewCell.self, forCellReuseIdentifier: "cell") 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 





    } 

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { 
     return UITableViewAutomaticDimension 
    } 

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     return UITableViewAutomaticDimension 
    } 

    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    return elements.count 
    } 


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 



     cell.textLabel?.numberOfLines = 0 



     cell.textLabel?.attributedText = addTextToAttribute(text: elements[indexPath.item]) 




     return cell 
    } 



    func addTextToAttribute(text : String) -> NSMutableAttributedString { 


     let mutString = NSMutableAttributedString() 

    let s = text.components(separatedBy: .whitespaces) 
     let attr: [String: AnyObject] = [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 20)] 

     for text in s { 


     mutString.append(NSAttributedString(string: "-" + text + "\n", attributes: attr)) 
     } 


     return mutString 
    } 

} 

enter image description here

関連する問題