首页 > 解决方案 > SwiftUI: Scaling in Xcode is not the same as on my iPhone

问题描述

import SwiftUI

let coloredNav = UINavigationBarAppearance()
let colors = AppData.getData()

var navBarTitle = "Nav Bar"
var navIconSelected = 0

struct ContentView: View {
    
    init() {
        //UITabBar.appearance().isTranslucent = false
        //UITabBar.appearance().barTintColor = .white
        
        coloredNav.backgroundColor = .white
       // UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor(colors.gray)]
        UINavigationBar.appearance().standardAppearance = coloredNav
        //UINavigationBar.appearance().titleTextAttributes = [.font : UIFont(name: "Georgia-Bold", size: 20)!]
    }
    
    
    var body: some View {
            TabView {
                NavigationView
                   {
                       VStack
                       {
                           Text("Home")
                       }
                       .navigationBarTitle("Home", displayMode:.inline)
                   }.tabItem {
                       Image(systemName:"house")
                   }
                   .tag(ViewTag.feed)
                
                NavigationView
                   {
                       VStack
                       {
                           Text("Messages")
                       }
                       .navigationBarTitle("Messages", displayMode:.inline)
                   }.tabItem {
                       Image(systemName:"text.bubble")
                   }
                   .tag(ViewTag.messages)
                NavigationView
                   {
                       VStack
                       {
                           Text("Phone")
                       }
                       .navigationBarTitle("Phone", displayMode:.inline)
                   }.tabItem {
                       Image(systemName:"phone")
                   }
                   .tag(ViewTag.call)
                NavigationView
                   {
                       VStack
                       {
                           Text("Notifications")
                       }
                       .navigationBarTitle("Notifications", displayMode:.inline)
                   }.tabItem {
                       Image(systemName:"bell")
                   }
                   .tag(ViewTag.notifications)
                NavigationView
                   {
                       ScrollView{
                           VStack
                           {
                               ProfileView(data: ProfileData.getPreviewData())
                                   //.padding([.top], 0)
                           }
                       }
                       
                       .navigationBarTitle("Profile", displayMode:.inline)
                   }.tabItem {
                       Image(systemName:"person.crop.circle")
                   }
                   .tag(ViewTag.profile)

            }
            .accentColor(colors.mid)
            //.accentColor(Color(red: 0.212, green: 0.275, blue: 0.282))
            .navigationBarTitle(navBarTitle)
            .navigationBarHidden(false)
            .navigationBarTitleDisplayMode(.inline)

            
        
        
    }
}

enum ViewTag {
        case feed
        case messages
        case call
        case notifications
        case profile
    }


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

This is my code ^ ^ ^

Basically, the sizing of the reviews widget is not the same on Xcode as it is when I run it on my phone. In Xcode I use the iPhone 11 simulator, and I also run the app on an iPhone 11.

Here is a comparison:

Here is the computer: https://i.stack.imgur.com/NYBuZ.png

Here is the phone: https://i.stack.imgur.com/8nmpJ.png

For this case specifically, it's not that big of a deal, but when dealing with more stuff, it really throws off the whole look. Any help is appreciated greatly. Thank you so much!

Also - if you are going to say it looks the same size, trust me, it's not. The same thing happens with text and shapes on a bigger scale, I just couldn't get a screenshot for that.

标签: iosswiftxcodeswiftui

解决方案


推荐阅读