简体   繁体   English

电晕按钮带有文字和图标?

[英]Corona button with text and icon?

Is it possible to have a Corona button with label text and a icon? 是否可以使用带标签文字和图标的电晕按钮? Something like this: 像这样的东西:

 ,===============,
 [   Action  •   ]
 `===============`

The bullet representing the icon, and Action representing the label text. 表示图标的项目符号和表示标签文本的Action

Is this possible to build buttons like this using the Corona widget library? 使用Corona小部件库可以构建这样的按钮吗?

To achieve that you'll need to code it yourself. 要实现这一点,您需要自己编写代码。 I personally like to do my buttons with an image and add an event listener to it, something like this: 我个人喜欢用图像做我的按钮并添加一个事件监听器,如下所示:

local function methodOnTap( event )
    print("Hey!! you tapped me!")
end

local buttonWithImage = display.newImage( "image.png")
buttonWithImage:addEventListener( "tap", methodOnTap )

this is a simple explanation on how to do a button with an image. 这是关于如何使用图像执行按钮的简单说明。

I think you want to do this for example, on a rectangle button I want a arrow image with "NEXT" text which will look like "NEXT->" 我想你想这样做,例如,在一个矩形按钮上,我想要一个带有“NEXT”文本的箭头图像,它看起来像“NEXT->”

There are two ways that you could do this: 有两种方法可以做到这一点:

  1. Create the button background image with the -> on it, and use that for the Next button. 使用 - >创建按钮背景图像,并将其用于下一步按钮。

  2. If you don't want to do that so you can keep the same background image for multiple buttons (ones with and without the ->), then create the widget button and position it. 如果您不想这样做,那么您可以为多个按钮(包含和不包含 - >的按钮)保留相同的背​​景图像,然后创建小部件按钮并定位它。 Put blank spaces in the text label for where you want the -> image to go, then calculate the position of the button and add a new image (not button) on top of it. 在文本标签中放置您希望 - >图像去的位置的空格,然后计算按钮的位置并在其上添加新图像(而不是按钮)。 Since I knew the buttons were never going to move and were always in the same position, it was fairly easy. 因为我知道按钮永远不会移动并且始终处于相同位置,所以它非常简单。

If you want to use also text in your button you can use a class and make the button with image and text! 如果你想在你的按钮中使用文本,你可以使用一个类,并使用图像和文本制作按钮! :) And then you call the function and use this class ;) :)然后你调用该函数并使用这个类;)

as shown over, you can call the class, if your class name is buttonC then it's going to be buttonC:addEventListener("tap",methodOnTap) 如上所示,您可以调用该类,如果您的类名是buttonC,那么它将是buttonC:addEventListener(“tap”,methodOnTap)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM