ios - Sprite 套件 : Label 'jumps' when text changes
<p><p>我有一个标签,显示自玩家第一次触摸屏幕以来在我的游戏中耗时。它显示秒和毫秒。我使用</p>将它定位在框架的中间
<pre><code> CGPointMake(CGRectGetMidX(self.frame)
</code></pre>
<p>问题是,并非所有数字看起来都具有相同的宽度(例如,1 小于 3)。这会导致我的标签在毫秒更新时从左到右快速跳跃一到两个像素。因为标签大小每次都会增加和减少,所以我的标签的 MidX 坐标会发生变化并导致我的标签移动。我希望它一直保持在同一个位置。</p>
<p>有人知道阻止它移动的解决方案吗?</p>
<p>编辑:标签代码</p>
<pre><code>-(SKLabelNode *) timeLabel
{
timeLabel = [ initWithFontNamed:@"Arial"];
timeLabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinY(self.frame);
timeLabel.fontColor = ;
timeLabel.fontSize = fontSize;
timeLabel.text = ;
return tijdLabel;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>尝试像这样将标签的对齐方式设置为居中:</p>
<pre><code>timeLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;
timeLabel.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;
</code></pre></p>
<p style="font-size: 20px;">关于ios -Sprite 套件 : Label'jumps'when text changes,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23322147/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23322147/
</a>
</p>
页:
[1]