0

When trying to center an image in a custom ImageElement in MonoTouch.Dialog, I'm having some issues. I've tried just about every technique in the book, from setting the image's center to the cell's center, adjusting content modes, etc.

My current approach:

public class MoveButtonElement : ImageElement, IElementSizing
    {
        UIActionSheet ActionSheet;
        UIActionSheetDelegate ActionSheetDelegate;

        static NSString key = new NSString ("ButtonElement");

        public MoveButtonElement () : base (null) { }

        protected override NSString CellKey 
        {
            get 
            {
                return key;
            }
        }

        public float GetHeight (UITableView tableView, NSIndexPath indexPath)
        {
            return 53;
        }

        public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
        {
            // SetupAndShowActionSheet (dvc);

        }

        public override UITableViewCell GetCell (UITableView tv)
        {
            var cell = base.GetCell (tv);

            cell.BackgroundView = null;
            cell.BackgroundColor = UIColor.Clear;
            cell.ContentMode = UIViewContentMode.Center;

            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            cell.ImageView.Image = Images.MoveVerseButton;
            cell.ImageView.ContentMode = UIViewContentMode.Redraw;

            return cell;
        }
      }
4

1 回答 1

0

当您的视图尚未设置框架时,您可能正在设置中心。调试您的 getcell 方法以检查框架属性。我有类似的问题,并通过代码设置 View.Frame 矩形来解决它们。X 是 (cell.Frame.Width - cell.Image.Width)/2,Y 也是如此。

于 2013-08-19T11:28:31.657 回答