简体   繁体   中英

how to give constraints for uilabel and uitextview in custom table cell by programmatically

Below mentioned link where my actual simulator screenshot . I have a query of how to adjust the label (brown colour) and textview (black colour) based upon the content from JSON , i did it on the static part of auto layout for UILabel and textview , how to code the constraints for UILabel and textview in custom cell such that it adjusted dynamically

在此处输入图片说明

awaiting for your awesome responses!!

You should work with Self-Sizing Table View Cells .

Set tableview Row height and estimated row height like,

tableView.estimatedRowHeight = 85.0
tableView.rowHeight = UITableViewAutomaticDimension

It must require proper autolayout when set height as UITableViewAutomaticDimension .

As Apple docs states,

To define the cell's height, you need an unbroken chain of constraints and views (with defined heights) to fill the area between the content view's top edge and its bottom edge. If your views have intrinsic content heights, the system uses those values. If not, you must add the appropriate height constraints, either to the views or to the content view itself.

You need to set unbroken chain of constraints that means first object must have top and last must have bottom and if there is only one object in cell then it must have both top and bottom.

You can refer Appcoda's tutorial for more details.

Hope this will help :)

I am giving my colors dynamically

[[UINavigationBar appearance] setBarTintColor:brownColor];
[[UINavigationBar appearance] setTintColor:whiteColor];

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