İçeriğe geç

UITableView dynamic row işlemi

Merhabalar bu yazımda iOS ile UITableView kullanarak otomatik satır yükseliği nasıl elde ederiz ? sorusuna yanıt bulacağız.

Bu işlemi default bir cell üzerinde gerçekleştireceğim. İşlem oldukça basit.

import UIKit

class mainVC: UIViewController {
    @IBOutlet weak var tblView: UITableView!
    var list:[String] = ["Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked","There are many variations of passages of Lorem Ipsum available, but the majority have suffered","It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy."]
    override func viewDidLoad() {
        tblView.estimatedRowHeight = 60.0
        tblView.rowHeight = UITableViewAutomaticDimension

extension mainVC: UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return list.count
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        cell?.textLabel?.text = list[indexPath.row]
        cell?.textLabel?.numberOfLines = 0
        cell?.textLabel?.textAlignment = .justified
        return cell!




Bu yazı yorumlara kapalı.

Copyright © 2020 Kenan Atmaca