Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.ios 在ImageElement中使图像居中_Xamarin.ios_Xamarin_Monotouch.dialog - Fatal编程技术网

Xamarin.ios 在ImageElement中使图像居中

Xamarin.ios 在ImageElement中使图像居中,xamarin.ios,xamarin,monotouch.dialog,Xamarin.ios,Xamarin,Monotouch.dialog,在MonoTouch.Dialog中尝试在自定义ImageElement中将图像居中时,我遇到了一些问题。我尝试了书中的每一种技术,从设置图像中心到单元格中心,调整内容模式,等等 我目前的做法是: public class MoveButtonElement : ImageElement, IElementSizing { UIActionSheet ActionSheet; UIActionSheetDelegate ActionSheetDelegat

在MonoTouch.Dialog中尝试在自定义ImageElement中将图像居中时,我遇到了一些问题。我尝试了书中的每一种技术,从设置图像中心到单元格中心,调整内容模式,等等

我目前的做法是:

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;
        }
      }

当你们的视图还并没有设置帧的时候,你们很可能正在设置中心。使用getcell方法检查框架属性。 我遇到了类似的问题,通过代码设置View.Frame矩形解决了这些问题。 X是(cell.Frame.Width-cell.Image.Width)/2,类似于Y