在Xcode中,在iPad上制作字体大于iPhone(Make Font Larger On iPad Than iPhone in Xcode)

编程入门 行业动态 更新时间:2024-10-11 19:13:44
在Xcode中,在iPad上制作字体大于iPhone(Make Font Larger On iPad Than iPhone in Xcode)

我使用Sprite Kit来添加一堆标签; 我想添加一些文本,但我想我必须将它们作为单独的SKLabelNode来执行,因为SpriteKit没有单独的大文本区域。

我添加了一个fontSize属性设置为32的SKLabelNode ,它在iPhone 5上看起来不错,但在iPad Retina上它看起来非常小。

我的问题是:如何为iPhone设置fontSize属性32 ,以及如何为64为iPad。

我的一个标签的代码片段:

SKLabelNode *line1 = [SKLabelNode labelNodeWithFontNamed:@"Kronoware"]; line1.text = @"FloppyPig.com"; line1.fontColor = [UIColor whiteColor]; line1.fontSize = 32; // This is what I want to make dynamic for iPhone and iPad. line1.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame); [self addChild:line1];

I'm using Sprite Kit to add a bunch of labels; I want to add a bunch of text but I guess I have to do them as individual SKLabelNode because SpriteKit doesn't have a single, large text area.

I am adding a SKLabelNode with the fontSize property set to 32, which looks fine on the iPhone 5 but it looks really small on the iPad Retina.

My questions is: How do I make fontSize property 32 for iPhone and something like 64 for iPad.

Snippet of my code for one label:

SKLabelNode *line1 = [SKLabelNode labelNodeWithFontNamed:@"Kronoware"]; line1.text = @"FloppyPig.com"; line1.fontColor = [UIColor whiteColor]; line1.fontSize = 32; // This is what I want to make dynamic for iPhone and iPad. line1.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame); [self addChild:line1];

最满意答案

使用UI_USER_INTERFACE_IDIOM()检查它是什么类型的设备,然后相应地设置fontSize 。 例如:

SKLabelNode *line1 = [SKLabelNode labelNodeWithFontNamed:@"Kronoware"]; line1.text = @"FloppyPig.com"; line1.fontColor = [UIColor whiteColor]; line1.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame); if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { line1.fontSize = 64; //iPad } else { line1.fontSize = 32; //iPhone } [self addChild:line1];

Use UI_USER_INTERFACE_IDIOM() to check what type of device it is and then set the fontSize accordingly. For example:

SKLabelNode *line1 = [SKLabelNode labelNodeWithFontNamed:@"Kronoware"]; line1.text = @"FloppyPig.com"; line1.fontColor = [UIColor whiteColor]; line1.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame); if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { line1.fontSize = 64; //iPad } else { line1.fontSize = 32; //iPhone } [self addChild:line1];

更多推荐

本文发布于:2023-08-06 19:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454447.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字体   iPad   Xcode   Larger   Font

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!