iOS Code Snippet Setting a button's image/icon

Discussion in 'iOS Code Snippets' started by Marcus Araujo, Apr 27, 2019.

  1. Marcus Araujo

    Marcus Araujo Member Licensed User

    Based on:
    https://stackoverflow.com/questions/36301791/how-to-set-the-icon-on-the-button-in-ios-using-swift

    Usage (tested with myButton as Button, myImage as B4XBitmap):
    Code:
    Dim no As NativeObject = Me
    no.RunMethod(
    "setButtonIcon:::"Array(myButton, myImage, no.MakeEdgeInsets(0080)))
    Code:
    Code:
    #IF OBJC
    - (void)setButtonIcon: (UIButton*)button :(UIImage*)icon :(UIEdgeInsets)edgeInsets
    {
        [button setImage:icon forState:UIControlStateNormal];
        [[button imageView] setContentMode: UIViewContentModeScaleAspectFit];
        [button setImageEdgeInsets: edgeInsets];
    }
    #END IF
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice