本文整理汇总了C#中UIImageView.AddConstraint方法的典型用法代码示例。如果您正苦于以下问题:C# UIImageView.AddConstraint方法的具体用法?C# UIImageView.AddConstraint怎么用?C# UIImageView.AddConstraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIImageView
的用法示例。
在下文中一共展示了UIImageView.AddConstraint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateImage
private void UpdateImage(string imageName, int widthRequest, int heightRequest, UIButton targetButton)
{
var assembly = typeof(App).GetTypeInfo().Assembly;
UIImage image = null;
if (imageName != null)
{
try
{
image = UIImage.FromResource(assembly, imageName);
}
catch (Exception)
{
var path = PCLStorage.FileSystem.Current.LocalStorage.Path;
var iPath = PCLStorage.PortablePath.Combine(path, imageName);
image = UIImage.FromFile(iPath);
}
}
var imageView = new UIImageView();
var widthCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, widthRequest);
var heightCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, heightRequest);
imageView.AddConstraint(widthCt);
imageView.AddConstraint(heightCt);
imageView.TranslatesAutoresizingMaskIntoConstraints = false;
imageView.Image = image;
imageView.ContentMode = UIViewContentMode.ScaleAspectFit;
targetButton.AddSubview(imageView);
switch (ImageButton.Orientation)
{
case TextAligment.Left:
{
targetButton.TitleEdgeInsets = new UIEdgeInsets(0, 20, 0, 0);
targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
}
break;
case TextAligment.Top:
{
targetButton.TitleEdgeInsets = new UIEdgeInsets(5, 0, 0, 0);
targetButton.VerticalAlignment = UIControlContentVerticalAlignment.Top;
}
break;
case TextAligment.Right:
{
var yCenterCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.CenterY, 1, 0);
var xLeftCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.Left, 1, 0);
targetButton.AddConstraint(yCenterCt);
targetButton.AddConstraint(xLeftCt);
targetButton.TitleEdgeInsets = new UIEdgeInsets(0, 0, 0, 20);
targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
}
break;
case TextAligment.Bottom:
{
var xCenterCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.CenterX, 1, 0);
var yTopCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.Top, 1, 0);
targetButton.AddConstraint(xCenterCt);
targetButton.AddConstraint(yTopCt);
targetButton.TitleEdgeInsets = new UIEdgeInsets(0, 0, 5, 0);
targetButton.VerticalAlignment = UIControlContentVerticalAlignment.Bottom;
}
break;
default:
throw new InvalidOperationException();
}
}