Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use image as button in ionic

My objective is to use image as a button in ionic. I first used a-tag to link between page. But when I clicked on the image. There is no button activated effect. So I switch to button-tag

I have tried using

<button class="button button-clear" style="background-image:url('img/myImage.jpg'); background-size:cover"></button>

But the button height stay the same. So it won't show full size image. I have tried

style="font-size:100px;"

and

style="line-height:100px;"

But nothing seems to work.

I also tried adding my own css

.Test-up {
  border :none;
  padding : 0px;
}

.Test-down {
  opacity: 0.5;
  border:0px;
  padding: 0px;
}

and added below code into my index.html

<button ng-mousedown="class='Test-down'" ng-mouseup="class='Test-up'" class="{{class}}" href="#">

and below code to my controller

$scope.class = "Test-up";

as I tried from http://codepen.io/Leiron/pen/ztawA But it doesn't work with ios or android. So what should I do?

like image 855
Wakeme UpNow Avatar asked Jun 04 '16 10:06

Wakeme UpNow


People also ask

How do you color buttons in ionic?

A color can be applied to an Ionic component in order to change the default colors using the color attribute. Notice in the buttons below that the text and background changes based on the color set. When there is no color set on the button it uses the primary color by default.


4 Answers

try this.

 <img src="img/myImage.jpg" style="width : 100% ; height : 100%" ng-click="nextpage()" >

this shoud to the trick you can have the height and width as your wish.

Make sure you give the correct path to src field.

like image 86
Mohan Gopi Avatar answered Oct 19 '22 01:10

Mohan Gopi


You can try this way -

<button  (click)="click()" block>
     <img src="assets/img/scan_btn.png">
</button>
like image 33
Bajrang Hudda Avatar answered Oct 19 '22 01:10

Bajrang Hudda


Ionic 2

Place your icons in www/assets/images then

<img src="assets/images/icon.png" style="width : 100% ; height : 100%" ng-click="nextpage()" >
like image 2
Shahab Rauf Avatar answered Oct 19 '22 01:10

Shahab Rauf


Ionic 4

<a routerLink="/user/details" routerDirection="forward">
   <img src='assets/images/icon.png'  />
</a>
like image 2
Ricky Levi Avatar answered Oct 18 '22 23:10

Ricky Levi