Xamarin.ios 在ImageElement中使图像居中
在MonoTouch.Dialog中尝试在自定义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
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