Fahad Rehman Fahad Rehman - 3 months ago 23
iOS Question

How to add the Left margin in UITableViewCell iOS Xamarin

How to add the left margin in UITableVIewCell Xamarin iOS.

I have tried the following ways but they does not work

public void initCell( CustomCommentInfo comment )
{
CoreGraphics.CGRect frame = this.ContentView.Frame;
if (comment.level > 0)
{
frame.X = frame.X + (comment.level * 10);
}
this.Frame = frame;
}


and

public void initCell( CustomCommentInfo comment )
{
CoreGraphics.CGRect frame = this.Frame;
if (comment.level > 0)
{
frame.X = frame.X + (comment.level * 10);
}
this.Frame = frame;
}


both of these does not work.

Answer

Ok i tried it with an other way that works

I added the view in the cell and added left margin constraints then keep the reference to the left margin in code and change it in code works

In designer.cs

UIKit.NSLayoutConstraint marginCommentCell { get; set; }

and in code behind file

if (comment.level > 0)
{       
    marginCommentCell.Constant += marginCommentCell.Constant *  comment.level;
}
else {
    marginCommentCell.Constant = 10; // constant value
}