kineticjs rect fillText [英] kineticjs rect fillText
问题描述
我有KineticJS rect已经填充'蓝'颜色,我想在这个rect框显示文本。但我的下面的代码不显示任何东西。此外,我需要在按钮点击时分配此标签文本,代码也在下面。
I have KineticJS rect already fill with 'blue' color, I want to show Text on this rect box. But my below code not showing anything. Also I need to assign this label text on button click, the code for the same is also below.
drawShape = new Kinetic.Rect({
id: shapeId,
name: shapeName,
x: 0,
y: 0,
width: 150,
height: 40,
fill: "#00D2FF",
stroke: "black",
strokeWidth: 3,
fillText: "Step" + stepNumber
});
function OnApplyPropertiesClick(){
drawShape.fillText(document.getElementById("txtLabel").value);
}
有什么帮助吗?
感谢
Biru
Thanks Biru
推荐答案
't认为你可以添加文本到矩形对象,只有填充类型:
I don't think you can add text to a rectangle object, only a fill type of:
[颜色,线性渐变,径向渐变或模式]
[color, linear gradient, radial gradient, or pattern]
为了解决这个问题,我创建了一个组,然后添加了一个矩形和文本对象,当我想要创建一个带有文本的矩形时:
To solve this i created a group, then added a rectangle and text object to it, when i wanted to create a rectangle with text on it:
var group = new Kinetic.Group({
});
var rectangle = new Kinetic.Rect({
x: 5,
y: 5,
width: 80,
height: 35,
fill: "green",
stroke: "black",
strokeWidth: 2
});
var rectangleText = new Kinetic.Text({
x: 15,
y: 10,
text: 'test',
fontSize: 20,
fontFamily: 'Calibri',
textFill: 'black'
});
group.add(rectangle);
group.add(rectangleText);
layer.add(group);
您应该能够调整侦听器,然后将其应用于此。
You should be able to adapt your listener to then apply it to this.
我做了一个jsfiddle来显示我的意思:
I've done a jsfiddle to show what i mean:
这篇关于kineticjs rect fillText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!