我想将imageview添加到我的视图中,但图像未显示。 我的代码有什么问题?谢谢你的帮助。Xamarin Studio:将UIimageView添加到UIView
...Constructor(UIImage _pickedImage......
UIImageView iv = new UIImageView (this.Bounds);
iv.Image = this.pickedImage;
this.AddSubview (iv);
iv.Release();
我想将imageview添加到我的视图中,但图像未显示。 我的代码有什么问题?谢谢你的帮助。Xamarin Studio:将UIimageView添加到UIView
...Constructor(UIImage _pickedImage......
UIImageView iv = new UIImageView (this.Bounds);
iv.Image = this.pickedImage;
this.AddSubview (iv);
iv.Release();
您的代码片段很短,但你应该不通话iv.Release();
因为你不平衡本地(ObjC)UIImageView
实例的引用计数。
事实上,你几乎从未已自行调用此方法,因为Xamarin.iOS有一个垃圾收集器(GC)会,处置的对象时,自动调用release
选择(就像一个retain
将完成时创建托管实例)。
今天我遇到了这个问题,发现这个问题还没有正确的答案,但如何解决它。所以为了将来的参考,我会解释我是如何解决它的。
我遍历包含图像的列表,如item
所示。 首先,创建的UIImageView
UIImageView imageView = new UIImageView();
然后我取的图像的字节数组,并将其转换为一个的UIImage
UIImage image = Utilities.ToImage(item.ImageBytesArray);
然后,设置的UIImageView与UIImage的
imageView.Image = image;
接下来是解决了我的主要问题,没有出现。所以,我们要得到屏幕尺寸,并将其存储在screen
var screen = UIScreen.MainScreen.Bounds;
设置的UIImageView的框架。这创建了可以看到的UIImageView。为了不重叠其他内容,我必须从顶部抵消400。
CGRect(xOffset, yOffset, width, height)
imageView.Frame = new CoreGraphics.CGRect(0, 400, screen.Size.Width, 300);
我用的是滚动型的,所以我把它添加到这一点。也可以是this
scrollView.Add(imageView);
的UIImageView的ImageView =新的UIImageView();
UIImage image = Utilities.ToImage(item.ImageBytesArray);
imageView.Image = image;
var screen = UIScreen.MainScreen.Bounds;
imageView.Frame = new CoreGraphics.CGRect(0,400,screen.Size.Width,300);
scrollView.Add(imageView);