using System; 
 | 
using Foundation; 
 | 
using Shared.IO; 
 | 
using UIKit; 
 | 
  
 | 
namespace Shared 
 | 
{ 
 | 
    /// <summary> 
 | 
    /// ImageView  
 | 
    /// </summary> 
 | 
    public class ImageView : View 
 | 
    { 
 | 
        MyImageView myImageView 
 | 
        { 
 | 
            get 
 | 
            { 
 | 
                return uiView as MyImageView; 
 | 
            } 
 | 
            set 
 | 
            { 
 | 
                uiView = value; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        /// <summary> 
 | 
        /// Initializes a new instance of the <see cref="Shared.Button"/> class. 
 | 
        /// </summary> 
 | 
        public ImageView() 
 | 
        { 
 | 
            myImageView = new MyImageView(this) { }; 
 | 
             
 | 
        } 
 | 
  
 | 
        internal string imagePath, tempImagePath; 
 | 
        /// <summary> 
 | 
        /// 非选中状态的背景图路径 
 | 
        /// </summary> 
 | 
        /// <value>The un selected image path.</value> 
 | 
        public string ImagePath 
 | 
        { 
 | 
            get 
 | 
            { 
 | 
                return imagePath; 
 | 
            } 
 | 
            set 
 | 
            { 
 | 
                tempImagePath = value; 
 | 
                if (!IsCanRefresh) 
 | 
                { 
 | 
                    return; 
 | 
                } 
 | 
                if (imageBytes != null) 
 | 
                { 
 | 
                    myImageView.SetBackgroundImage(UIImage.LoadFromData(NSData.FromArray(imageBytes)), UIControlState.Normal); 
 | 
                    return; 
 | 
                } 
 | 
                if (ImagePath == value) 
 | 
                { 
 | 
                    return; 
 | 
                } 
 | 
                imagePath = value; 
 | 
                myImageView.SetBackgroundImage(UIImage.FromFile(FileUtils.GetImageFilePath(imagePath)), UIControlState.Normal); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        byte[] imageBytes; 
 | 
        public byte[] ImageBytes 
 | 
        { 
 | 
            get 
 | 
            { 
 | 
                return imageBytes; 
 | 
            } 
 | 
            set 
 | 
            { 
 | 
                imageBytes = value; 
 | 
                ImagePath = tempImagePath; 
 | 
            } 
 | 
        } 
 | 
  
 | 
  
 | 
        public override void Refresh() 
 | 
        { 
 | 
            base.Refresh(); 
 | 
  
 | 
            ImagePath = tempImagePath; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    class MyImageView : UIKit.UIButton 
 | 
    { 
 | 
        [Weak] View view; 
 | 
        public MyImageView(View view) 
 | 
        { 
 | 
            this.view = view; 
 | 
        } 
 | 
        /// <summary> 
 | 
        /// 点击开始 
 | 
        /// </summary> 
 | 
        /// <param name="touches">Touches.</param> 
 | 
        /// <param name="evt">Evt.</param> 
 | 
        public override void TouchesBegan(NSSet touches, UIEvent evt) 
 | 
        { 
 | 
            view?.TouchEvent(EventActions.Down, (touches.AnyObject as UITouch).LocationInView(this)); 
 | 
        } 
 | 
        /// <summary> 
 | 
        ///  移动 
 | 
        /// </summary> 
 | 
        /// <param name="touches">Touches.</param> 
 | 
        /// <param name="evt">Evt.</param> 
 | 
        public override void TouchesMoved(NSSet touches, UIEvent evt) 
 | 
        { 
 | 
            view?.TouchEvent(EventActions.Move, (touches.AnyObject as UITouch).LocationInView(this)); 
 | 
        } 
 | 
  
 | 
        /// <summary> 
 | 
        /// 点击弹起 
 | 
        /// </summary> 
 | 
        /// <param name="touches">Touches.</param> 
 | 
        /// <param name="evt">Evt.</param> 
 | 
        public override void TouchesEnded(NSSet touches, UIEvent evt) 
 | 
        { 
 | 
            view?.TouchEvent(EventActions.Up, (touches.AnyObject as UITouch).LocationInView(this)); 
 | 
        } 
 | 
  
 | 
        public override void TouchesCancelled(NSSet touches, UIEvent evt) 
 | 
        { 
 | 
            view?.TouchEvent(EventActions.Cancel, (touches.AnyObject as UITouch).LocationInView(this)); 
 | 
        } 
 | 
    } 
 | 
} 
 |