这是一个链接:http: //jsfiddle.net/6VRxE/11/
我有一个固定大小的文本框,我想动态更改文本、文本大小和填充,以便文本适合矩形并垂直对齐。
var messageText = new Kinetic.Text({
x: .25*stage.getWidth(),
y: .25*stage.getHeight(),
width: .5*stage.getWidth(),
height: .5*stage.getHeight(),
fontSize: 10,
fontFamily: 'Lucida Grande',
text: 'Hello, click to continue',
align: 'center',
textFill: '#006400',
stroke: 'gray',
draggable: true,
fill: 'white',
});
我想用这样的事件或函数更改文本:
messageText.on('click',function(){
messageText.setText('hi');
messageText.setFontSize(messageText.getHeight()/2);
messageText.setPadding(messageText.getHeight()/5); //this was one possibility to do some alignment but doesn't work great
stage.draw();
});
有没有人有一个很好的解决方案来计算取决于长度的文本大小?