在ImageElement中居中放置图像
问题描述:
试图在MonoTouch.Dialog中的自定义ImageElement中居中放置图像时,出现了一些问题。我已经尝试过几乎每一项技术都在本书中,从设置图像的中心到小区的中心,调整内容模式等在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;
}
}
答
您problably设置在力矩中心当你的意见尚未设定框架。 Debbug你的getcell方法来检查帧属性。 我有类似的问题,并通过代码设置View.Frame矩形来解决它们。 X is(cell.Frame.Width - cell.Image.Width)/ 2,类似于Y.
不幸的是,无法让这个宝宝上班。 – pierceboggan