public static void SetImageFor(string imagePath, UIButton button, UIControlState state)
 {
     using (UIImage img = UIImage.FromFile(imagePath)) {
         Assert.NotNull(img);
         button.SetImage(img, state);
     }
 }
Example #2
0
 public virtual void SetTitleTextAttributes(TextAttributes attributes, UIControlState state)
 {
     if (attributes == null)
         throw new ArgumentNullException ("attributes");
     using (var dict = attributes.Dictionary){
         _SetTitleTextAttributes (dict, state);
     }
 }
Example #3
0
            public void SetScopeBarButtonTitle(TextAttributes attributes, UIControlState state)
            {
                if (attributes == null)
                    throw new ArgumentNullException ("attributes");

                using (var dict = attributes.Dictionary) {
                    _SetScopeBarButtonTitle (dict, state);
                }
            }
 public MvxUIButtonTitleTargetBinding(UIButton button, UIControlState state = UIControlState.Normal)
     : base(button)
 {
     this._state = state;
     if (button == null)
     {
         MvxBindingTrace.Trace(MvxTraceLevel.Error, "Error - UIButton is null in MvxUIButtonTitleTargetBinding");
     }
 }
        public static void SetTitle(this UIButton button, object source, PropertyInfo property,
            UIControlState state = UIControlState.Normal)
        {
            var text = property.GetValue(source).ToString();

            if (button.Title(state) != text)
            {
                button.InvokeOnMainThread(() => button.SetTitle(text, state));
            }
        }
Example #6
0
        public static Task<ImageDownloadResult> SetBackgroundImageAsync(this UIButton button, NSUrl url, UIControlState state, UIImage placeholder = null, SDWebImageOptions options = SDWebImageOptions.None)
        {
            var tcs = new TaskCompletionSource<ImageDownloadResult> ();

            SDWebImageManager.SharedManager.SetBackgroundImage (button, url, state, placeholder, options, (image, error, cacheType) => {
                if (image == null) {
                    tcs.SetException (new NSErrorException (error));
                    return;
                }
                tcs.SetResult (new ImageDownloadResult (image, cacheType));
            });

            return tcs.Task;
        }
        public static Action BindTitle(this UIButton button, 
                    INotifyPropertyChanged source, 
                    string propertyName,
                    UIControlState state = UIControlState.Normal)
        {
            var property = source.GetProperty(propertyName);

            button.SetTitle (source, property, state);

            var handler = new PropertyChangedEventHandler(
                (s, e) =>
                {
                    if (e.PropertyName == propertyName)
                    {
                        button.SetTitle (source, property, state);
                    }
                }
            );

            source.PropertyChanged += handler;

            return new Action(() => source.PropertyChanged -= handler);
        }
Example #8
0
 public TextAttributes GetScopeBarButtonTitleTextAttributes(UIControlState state)
 {
     using (var d = _GetScopeBarButtonTitleTextAttributes (state)) {
         return new TextAttributes (d);
     }
 }
 /// <summary>
 /// Loads an image from a bundle given the supplied image name, resizes it to the
 /// height and width request and sets it into a <see cref="UIButton"/>.
 /// </summary>
 /// <param name="source">The <see cref="ImageSource"/> to load the image from.</param>
 /// <param name="widthRequest">The requested image width.</param>
 /// <param name="heightRequest">The requested image height.</param>
 /// <param name="targetButton">A <see cref="UIButton"/> to set the image into.</param>
 /// <returns>A <see cref="Task"/> for the awaited operation.</returns>
 private async static Task SetImageAsync(ImageSource source, int widthRequest, int heightRequest, UIButton targetButton, UIControlState state = UIControlState.Normal)
 {
     var handler = GetHandler(source);
     using (UIImage image = await handler.LoadImageAsync(source))
     {
         UIImage scaled = image;
         if (heightRequest > 0 && widthRequest > 0 && (image.Size.Height != heightRequest || image.Size.Width != widthRequest))
         {
             scaled = scaled.Scale(new CGSize(widthRequest, heightRequest));
         }
         targetButton.SetImage(scaled.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), state);   
     }
 }
Example #10
0
 public static void SetImage(this UIButton button, NSUrl url, UIControlState state, UIImage placeholder = null, SDWebImageOptions options = SDWebImageOptions.None, SDWebImageCompletedBlock completed = null)
 {
     SDWebImageManager.SharedManager.SetImage (button, url, state, placeholder, options, completed);
 }
Example #11
0
 public virtual TextAttributes GetTitleTextAttributes(UIControlState state)
 {
     using (var d = _GetTitleTextAttributes (state)){
         return new TextAttributes (d);
     }
 }
Example #12
0
 public override String Title(UIControlState state)
 {
     return base.GetAttributedTitle(state).Value;
 }
Example #13
0
		public void SetBackgroundColor(UIColor color, UIControlState state){
			switch (state) {
				case UIControlState.Highlighted:
				case UIControlState.Selected:
					selectedColor = color;
					break;
				case UIControlState.Disabled:
					disabledColor = color;
					break;
				default:
					normalColor = color;
					break;
			}

			Initialize ();
		}
Example #14
0
        public virtual void MouseMove(Vector2 mouse)
        {
            if (IsOver(mouse.X, mouse.Y))
              {
            switch (State)
            {
              case UIControlState.Normal:
            State = UIControlState.Highlighted;
            break;
            }
              }
              else
              {
            switch (State)
            {
              case UIControlState.Highlighted:
            State = UIControlState.Normal;
            break;
            }
              }

              Game1.BlockNonUIEvents = IsOver(mouse.X, mouse.Y);
        }
Example #15
0
 public override void SetTitle(string title, UIControlState forState)
 {
     base.SetTitle(title, forState);
     UpdateLayout();
 }
        /// <summary>
        /// Loads an image from a bundle given the supplied image name, resizes it to the
        /// height and width request and sets it into a <see cref="T:UIKit.UIButton"/>.
        /// </summary>
        /// <param name="source">The <see cref="T:Xamarin.Forms.ImageSource"/> to load the image from.</param>
        /// <param name="widthRequest">The requested image width.</param>
        /// <param name="heightRequest">The requested image height.</param>
        /// <param name="targetButton">A <see cref="T:UIKit.UIButton"/> to set the image into.</param>
        /// <param name="state">The state.</param>
        /// <param name="tintColor">Color of the tint.</param>
        private static async Task SetImageAsync(ImageSource source,
                                                int widthRequest,
                                                int heightRequest,
                                                UIButton targetButton,
                                                UIControlState state = UIControlState.Normal,
                                                UIColor tintColor = null)
        {
            var handler = GetHandler(source);
            using(var uiImage1 = await handler.LoadImageAsync(source, new CancellationToken(), 1f))
            {
                var uiImage2 = uiImage1;
                if(heightRequest > 0 && widthRequest > 0 && (uiImage1.Size.Height != heightRequest || uiImage1.Size.Width != widthRequest))
                {
                    // squish it so it fits within the size you requested.
                    uiImage2 = uiImage2.Scale(new CGSize(widthRequest, heightRequest));
                }

                var width = uiImage2.CGImage.Width;
                var uiImage3 = ClipToCircle(uiImage2, width, (float)width / 2);

                if(tintColor != null)
                {
                    targetButton.TintColor = tintColor;
                    targetButton.SetImage(uiImage3.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), state);
                }
                else
                {
                    targetButton.SetImage(uiImage3.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), state);
                }
            }
        }
Example #17
0
 public static void SetImage(this UIButton button, string url, UIControlState state, UIImage placeholder = null, SDWebImageOptions options = SDWebImageOptions.None, SDWebImageCompletedBlock completed = null)
 {
     if (!Uri.IsWellFormedUriString (url, UriKind.Absolute)) return;
     SDWebImageManager.SharedManager.SetImage (button, NSUrl.FromString (url), state, placeholder, options, completed);
 }
Example #18
0
 public void SetTitleTextAttributes(TextAttributes attributes, UIControlState state)
 {
     using (var dict = attributes == null ? null : attributes.Dictionary)
         _SetTitleTextAttributes (dict, state);
 }
Example #19
0
 public static UIButton SetTitleWithResize(this UIButton button, UIView view, string title, UIControlState state)
 {
     var frame = button.Frame;
     var newSize = view.StringSize (title, button.Font);
     var newFrame = new RectangleF (frame.Left, frame.Top, newSize.Width + 6, frame.Height);
     button.Frame = newFrame;
     button.SetTitle (title, state);
     return button;
 }
Example #20
0
 public override void SetTitle(String title, UIControlState forState)
 {
     base.SetAttributedTitle(this.Compute(title), forState);
 }
Example #21
0
        public static Task<ImageDownloadResult> SetBackgroundImageAsync(this UIButton button, string url, UIControlState state, UIImage placeholder = null, SDWebImageOptions options = SDWebImageOptions.None)
        {
            if (!Uri.IsWellFormedUriString (url, UriKind.Absolute)) throw new Exception (String.Format ("Malformed url: {0}", url));

            return SetImageAsync (button, NSUrl.FromString (url), state, placeholder, options);
        }