Home > OS >  How can I make my kivy layout the same scale on iPad and iPhone?
How can I make my kivy layout the same scale on iPad and iPhone?

Time:10-12

I have got my app working on my iPhone at a scale that looks good. I have run it now on my iPad and everything is much more spaced out and the text appears much smaller. I have had the app open on both devices and held them next to each other and it appears as though the text size is actually the same on both. Obviously it looks smaller on a bigger screen.

Another thing that is kind of strange is that on the iPad, the app screen fills the whole screen entirely, but on the iPhone, it kind of runs shy of the top and bottom by about 10% each way.

I have done a fair bit of looking around at apple's stuff and on kivy docs but can't see anything conclusive.

How may I make it so they're are automatically scaled on any iOS device? Also, how can I make the app fill out the whole screen on the iPhone? Is it something in Xcode that needs to be changed, or is it a kivy thing? I am a bit lost here. Any help will be much appreciated thank you.

EDIT: I will include a widget from one of my kivy pages, maybe the problem is in the way i'm laying it out.

BoxLayout:
    pos_hint: {"top": .9, "center_x": .5}
    size_hint: 1, .3
    size_hint_y: None
    height: 450 # set 330 for iphone
    ScrollView:
        Label:
            id: brief_res_1
            font_size: '11sp'
            do_scroll_x: True
            size_hint_y: None
            size_hint_x: None
            size: self.texture_size
            halign: "left"
            valign: "center"
            text:

CodePudding user response:

I suggest using size_hint and pos_hint for widgets in your kv, and use the kivy.metrics (sp) for font_size.

CodePudding user response:

As of what I know, there's currently no concrete answer to your problem, due to the differences between iPhones' and iPads' screen sizes and ratios. There is, however, 2 solutions that I suggest you trying:

  • The platform variable from kivy.utils stores the name of the platform that it's running on. If I'm correct, if your app is running on an iPhone then it should return "ios", and "unknown" for an iPad, because it apparently does not check for "ipados". If it's true, you should make a separated kivy script from your iOS-compatible one that prefers the iPad screen size, and afterwards you can add a check, something like this:
from kivy.utils import platform
from kivy.lang import Builder

if platform == "ios":
    Builder.load_file("ios.kv")
elif platform == "unknown":
    Builder.load_file("ipados.kv")
else:
    # your preferences...
  • If for whatever reason platform returns "ios" on an iPad, then I say you should get the screen resolution first, and then do a check similar to the above example, something like this:
from kivy.core.window import Window


Window.fullscreen = True
Window.maximize()

resolution = Window.size
Window.fullscreen = False

if resolution[0] / resolution[1] < 1:
    Builder.load_file("ios.kv")
else:
    Builder.load_file("ipados.kv") 
  • Related