I want to create a view like this to show some long text. got some pods for this but i want to this do programatically.
thanks in advance.
first image -> the view before tap.
second image -> view after tap.
I want to create a view like this to show some long text. got some pods for this but i want to this do programatically.
thanks in advance.
first image -> the view before tap.
second image -> view after tap.
If you need a quick working solution, you can try this.
create a TableViewCell with two labels: title label with Fixed height (let's say 48) and description label (multiline)
Maintain heights for each cell in an array, by default keep it the height of title label, just to show the title label (say itemHeights = [48,48,48]
When you select cell, inside the delegate method "didSelectRowAt:", toggle the height
if self.itemHeights[indexPath.row] == UITableViewAutomaticDimension {
self.itemHeights[indexPath.row] = 48
} else {
self.itemHeights[indexPath.row] = UITableViewAutomaticDimension
}
self.tableView.reloadRows(at: [indexPath], with: .automatic)
Inside delegate method "heightForRowAt:", return the updated height
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return self.itemHeights[indexPath.row]
}
Note: this is just a workaround which gives you almost the same result but with some jerky animation.