Search code examples
nativescriptangular2-nativescriptnativescript-plugin

Nativescript radiobutton


I am developing a NativeScript application. I want to use radiobutton functionality in my application.

I have tried to achieve this by using "nativescript-radiobutton" plugin, but it doesn't support in iOS.

Is there any solution through which it works for both Android and iOS platform?

Thank you in advance.


Solution

  • Use this Html for the radio button -

    <Label text="{{ checkYes ? '&#xf192;' : '&#xf10c;'}}" 
           class="{{ checkYes ? 'fontawesome' : 'radioBefore'}}" 
           (tap)="changeAction()">
    </Label>
    

    Apply these two classes for Font Awesome -

    .font-awesome {
       font-family: "fontawesome-webfont";
       font-size: 24;
    }
    
    .radioBefore {
       font-family: "fontawesome-webfont";
       font-size: 24;
    }
    

    Add Font-awesome.ttf file in fonts folder and then change the radio buttons selected or unselected with changeAction()

    Function - Initialize this.changeYes = true

     changeGenderMale(){
        if(this.changeYes == true)
          this.changeYes = false;
        else
          this.changeYes = true;
     }