Egret動態設置按鈕的圖片


參考:

動態設置Button按鈕的狀態圖片

 

按鈕有3個狀態,up down disabled。這里區別於source,source.down,source.disabled,而是每個狀態單獨一個image。

且每個單獨的<image>標簽有一個特別的屬性includeIn,這里表示該圖片的狀態。

	<e:RadioButton id="testBtn" label="" x="398" y="62" anchorOffsetX="0" width="142" anchorOffsetY="0" height="62">
		<e:skinName>
		<e:Skin states="up,down,disabled">
			<e:Image width="100%" height="100%" source="book_scale1_0_png" includeIn="up" id="radio_pic_up"/>
			<e:Image width="100%" height="100%" source="book_scale1_1_png" includeIn="down" id="radio_pic_down"/>
			<e:Image width="100%" height="100%" source="book_scale1_2_png" includeIn="disabled" id="radio_pic_disabled"/>
			<e:Label id="labelDisplay" horizontalCenter="0" verticalCenter="0"/>
		</e:Skin>
		</e:skinName>
	</e:RadioButton>

 

代碼中根據圖片id獲取按鈕的圖片["radio_pic_up"],再賦值新的texture就可以動態改變按鈕的圖片了。

this.testBtn["radio_pic_up"].texture = RES.getRes("0_png");
this.testBtn["radio_pic_down"].texture = RES.getRes("1_png");
this.testBtn["radio_pic_disabled"].texture = RES.getRes("2_png");

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM