简体   繁体   中英

Label are overlapping even after adding constraint in Xamarin.IOS

Labels are overlapping in Xamarin.IOS and dimension also not expanding with respect to content.

Code in ViewController:

   List<class> listofdata = databaseconnectivity.GetListofData(1);
   TableViewSource tableViewsourceObj = new TableViewSource(listofdata, this);
   tableView.Source = tableViewsourceObj;
   tableView.RowHeight = UITableView.AutomaticDimension;

Code in GetCell method of TableView Source

  var cell = tableView.DequeueReusableCell((Foundation.NSString)"TVCellIdentifier");
  var cell2 = (VersesTvcCell)cell;   
  cell2.UpdateCell(listofdata[indexPath.Row].field1, listofdata[indexPath.Row].field2);
  return cell2;

Code in UpdateCell method of UITableViewCell

   Label1.Text = field1;
   Label2.Text = field2;

Result Image

Image of constraints of labels

移除两个标签的顶部对齐并增加它们之间的垂直间距。

You need to set constraint as below .

  1. FirstLabel - Leading, Trailing, Top, (Bottom with SecondLabel).
  2. SecondLabel - Leading, Trailing, (Bottom with ContentView)
  3. Got error, it is about content hugging priority . You can resolve using xcode correction or using set vertical priority higher to secondLabel.

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