当前位置: 首页>>代码示例>>C#>>正文


C# UIImageView.AddConstraint方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:NamXH,项目名称:Orchard,代码行数:73,代码来源:ImageButtonRenderer.cs


注:本文中的UIImageView.AddConstraint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。