Adapt SwiftUI app for iPad, Landscape, and Dark Mode | Todo List #6
Summary
TLDR在这个视频中,Nick 通过 Swiffle Thinking 引导观众如何使他们的应用程序适应不同的运行环境。他们首先在 iPhone 上运行应用,确保它在竖屏和横屏模式下,以及在浅色和深色模式中都能良好运行。Nick 展示了如何通过调整 Swift UI 中的颜色和样式,使应用在不同模式下都能保持美观。他们还讨论了如何在 iPad 上测试应用,并解决了导航视图在 iPad 上的显示问题,以确保应用在不同设备上都能提供一致的用户体验。最后,Nick 强调了对应用进行彻底测试的重要性,并鼓励开发者关注细节,以确保他们的应用在各种条件下都能表现出色。
Takeaways
- 📱 在视频中,Nick讨论了如何使应用程序适应不同的部署方式,包括横竖屏、iPhone和iPad以及明暗模式。
- 🖥️ 首先,他们检查了应用在iPhone上的显示效果,确保在明暗模式下颜色和布局都看起来良好。
- 🔄 Nick展示了如何通过改变颜色的appearance属性来适配暗模式,使得颜色在不同模式下都能保持易读性。
- 🎨 他们对应用的辅助颜色进行了调整,以确保在暗模式下更加醒目和易读。
- 📊 为了改善用户体验,Nick还调整了添加视图中占位符文本的背景颜色,使用了动态颜色来自动适应明暗模式。
- 📲 在模拟器上测试了应用在不同设备方向(横屏和竖屏)下的表现,并进行了必要的调整。
- 📐 通过设置最大宽度,Nick限制了“无项目”区域在横屏或大设备上的宽度,以保持布局的整洁。
- 🔧 在iPad上测试应用时,发现并修复了由于导航视图在iPad上的默认样式导致的问题,改为了堆叠导航视图样式。
- 📱 确认了应用在iPad上的表现,包括在横竖屏模式下的外观和功能。
- 🔄 强调了应用的动态颜色功能,确保了在不同模式下都能提供良好的用户体验。
- 🛠️ 通过SwiftUI的动态颜色和布局工具,简化了适配不同设备和模式的过程。
- 📹 整个视频是一个实操教程,向观众展示了如何对一个简单的应用程序进行多设备和多模式的适配。
Q & A
在视频中,Nick提到了哪些设备和模式,以确保应用程序的适配性?
-Nick提到了iPhone和iPad设备,以及横屏和竖屏模式。此外,还提到了亮模式(light mode)和暗模式(dark mode)以确保应用程序在不同环境下的外观和性能。
在视频中,应用程序最初在哪种模式下运行,后来又切换到了哪种模式?
-最初,应用程序在亮模式(light mode)下运行,后来Nick切换到了暗模式(dark mode)以测试应用程序在暗背景下的表现。
为了改善暗模式下的可读性,Nick对应用程序的哪些颜色进行了调整?
-为了改善暗模式下的可读性,Nick调整了紫色和栗色(maroon)的强调色,将它们改为了更亮的紫色和草莓色(strawberry),以确保在黑色背景上更容易阅读。
在iPad上运行应用程序时,遇到了什么问题,又是如何解决的?
-在iPad上运行应用程序时,遇到了导航视图(navigation view)样式问题,iPad默认使用了带有侧边栏的样式,这并不适合他们的应用程序。通过在ToDo List App.swift文件中的导航视图上设置`.stackNavigationViewStyle()`,解决了这个问题。
在视频中,Nick提到了哪些Swift UI的颜色特性?
-Nick提到了Swift UI中的动态颜色(dynamic colors),这些颜色会根据亮模式和暗模式自动改变,如主色(primary color)和次色(secondary color)。此外,还提到了系统颜色(system colors),如`secondarySystemBackground`,它们也是自动适应不同模式的。
为了测试应用程序在不同设备和模式下的表现,Nick使用了哪些工具?
-Nick使用了模拟器(simulator)来测试应用程序在不同设备和模式下的表现。他还提到了使用Xcode的画布(canvas)功能,可以在不运行模拟器的情况下预览应用程序在亮模式和暗模式下的效果。
在调整应用程序以适应iPad时,Nick对导航视图做了哪些改变?
-为了使导航视图在iPad上正确显示,Nick在ToDo List App.swift文件中的导航视图上添加了`.stackNavigationViewStyle()`,以确保导航视图使用标准的堆叠样式,而不是iPad默认的侧边栏样式。
在视频中,Nick提到了如何调整应用程序以适应横屏模式?
-Nick提到,由于在设计屏幕布局时使用了如`maxWidth`这样的Swift UI布局特性,应用程序能够自动适应横屏模式。他还特别调整了“无项目”视图的宽度,设置了最大宽度为400,以确保在横屏或大设备上显示效果更佳。
在视频中,Nick是如何处理应用程序在暗模式下的文本字段和占位符文本的可读性问题的?
-Nick发现在暗模式下,文本字段的占位符文本颜色变得不明显,因此他决定使用动态颜色来自定义文本字段的背景颜色,以提高占位符文本的可读性。
在视频中,Nick是否提到了对应用程序进行测试的重要性?
-是的,Nick提到了对应用程序进行测试的重要性,他强调了确保应用程序在不同设备、模式和方向下都能良好运行和显示是至关重要的。
在视频中,Nick是否提到了如何为应用程序添加对不同语言的支持?
-不,Nick在视频中没有提到为应用程序添加对不同语言的支持。他主要关注的是应用程序在不同设备、模式和方向下的适配性。
在视频中,Nick是否提到了如何处理应用程序在不同屏幕尺寸下的布局问题?
-是的,Nick提到了在不同屏幕尺寸下,如iPad的12.9英寸屏幕上,应用程序的布局问题。他通过设置最大宽度来限制某些视图的宽度,以确保布局在不同屏幕尺寸下都能保持合理。
Outlines
📱 适配不同模式和设备
Nick介绍了如何使应用程序在不同的模式和设备上运行良好。他提到,到目前为止,他们只在iPhone上以竖屏、浅色模式测试了应用。本视频的目标是让应用在各种部署方式下都能适应,包括横屏和竖屏模式,以及在iPhone和iPad上的表现,还有在浅色和深色模式下的外观。他首先在iPhone 12的模拟器上运行应用,并检查了浅色模式下的颜色方案,然后切换到深色模式,并调整了颜色以适应深色背景。
🖌️ 调整颜色和动态背景
Nick展示了如何在深色模式下调整应用的颜色,以提高可读性。他通过在Assets.xcassets文件夹中修改强调色和次要强调色,使它们在深色模式下更亮。接着,他解决了深色模式下占位符文本不可见的问题,通过使用动态颜色来更改背景色,确保文本在任何模式下都清晰可见。他还提到了在模拟器上测试应用,并在Canvas上快速预览不同模式的方法。
📱 适配横屏和iPad设备
为了确保应用在横屏和iPad上也能良好运行,Nick对应用进行了测试和调整。他首先限制了'no items'区域的宽度,以避免在横屏或大设备上显得过宽。然后,他在iPad Pro 12.9英寸模拟器上运行了应用,并解决了由于iPad上导航视图默认样式不同导致的问题,通过设置导航视图样式为'stack'来恢复期望的界面布局。最后,他确认了应用在横屏模式下的表现,并强调了应用现在已准备好发布。
Mindmap
Keywords
💡适配性
💡Swift UI
💡暗模式
💡动态颜色
💡模拟器
💡导航视图
💡iPad Pro
💡横屏模式
💡资产目录
💡系统颜色
💡最大宽度
Highlights
在本课程中,我们之前只在iPhone上以竖屏模式和浅色模式运行了我们的应用程序。
本视频我们将使应用程序适应不同的部署方式,包括横竖屏和明暗模式。
首先在iPhone 12模拟器上以浅色模式运行应用程序,检查颜色和布局。
在深色模式下,文本使用的主要颜色会自动调整,但紫色在黑色背景上阅读困难。
为了改善深色模式下的可读性,调整了紫色和褐红色为更浅的色调。
使用Swift UI的动态颜色,如系统背景色,以在明暗模式间自动切换。
在iPad上测试应用程序,发现导航视图默认样式在iPad上显示为侧边栏。
通过设置导航视图样式为stack,解决了iPad上的导航问题。
限制了“无项目”视图的最大宽度,以适应不同屏幕尺寸和方向。
在横屏模式下测试应用程序,确保布局和功能正常。
在iPad上运行应用程序,确认在大屏幕上的显示效果良好。
调整了应用程序的颜色方案,以确保在浅色和深色模式下都具有良好的可读性和美观性。
通过模拟器和Xcode的Canvas预览功能,可以快速检查应用程序在不同模式下的表现。
使用Swift UI的资产和外观设置,可以轻松调整应用程序的颜色以适应不同的显示模式。
在iPad上运行时,需要特别注意导航视图的样式,以确保用户体验。
通过简单的代码更改,可以调整应用程序以适应不同的设备和屏幕尺寸。
应用程序的简洁性意味着在适配不同模式和设备时不需要太多更改。
视频的最后,确认了应用程序在所有测试条件下的外观和功能都符合预期。
Transcripts
[Music]
what's up everyone
i'm nick this is swiffle thinking and so
far in this course
we have only run our app on an iphone
in portrait mode in light mode and in
this video we're going to make our app
adaptable for all the different ways we
might deploy it
and that means we're going to make sure
that our app looks good and runs well
in portrait as well as landscape mode it
runs
well on the iphone as well as the ipad
and it looks good
in light mode as well as dark mode
welcome back guys uh in this quick video
we're just gonna do a little bit of
cleanup we're just gonna run through our
app and make sure it looks good
in dark mode as well as on the ipad
and in landscape mode now this is a very
simple app so i don't think we're gonna
have much to actually do
but i wanted to just run through this
process for those of you who have maybe
never dealt with any of this before and
this is one of your first apps
so let's start by just running our app
as is on the iphone
use the iphone 12
and open it up on a simulator of course
not in the preview
and we're going to look at the colors
first so the phone probably is going to
be in light mode to begin with
and we have our normal colors we have
the purple going to maroon
we have white backgrounds black text
this all looks good
if i go to the add screen again white
backgrounds black text
we have a gray text field which looks
pretty good and a purple save button
i don't think we have any issues here
with the light mode but let's change
our app here to go into dark mode so on
the simulator i'm going to go to open
these settings
and in and in your settings on the
simulator if you scroll down there
should be a
developer tab here so click open on the
developer
and then you can change the appearance
there to dark mode
so now the simulator should be in dark
mode and let's open back
up our app again and see what it looks
like
well immediately we can see that the
background is now black which is good
the text is white and that's because all
of these texts are using the dot
primary color and if you followed my
swift ui boot camp
you're well aware that the primary and
the secondary colors
are naturally dynamic so that they
change between light and dark mode
and this is good i do notice here that
our
colors the purple i can still see it
but it is a little harder to read now
that we are in dark mode because this is
a dark purple on a black background
so i think we should change that quickly
so let's go into the assets.xc assets
folder
in the last video we set up our accent
color
and if i open up the inspector on the
right side
uh and i click on this color right now
the appearances
is none and that means we have a
universal color so this accent color is
universal gonna be dark purple so on
light mode in dark mode no matter what
mode it is it's going to be this dark
purple
but if we change the appearances we can
add an any and
dark and then we have a different
appearance between
any which is going to be our light mode
and the dark mode so in the dark mode
instead of having this dark purple i'm
going to make it a little bit more of a
lighter purple so that it's a little bit
easier to read on this dark background
so i'm going to click on the dark one
i'm going to click on the show color
panel
and we're using this dark purple but i'm
going to use maybe this lighter
grape so i think that will be a little
easier to read on
the dark background i'm going to close
that i'm going to do the same thing for
the secondary accent color
so click that i'm going to click on the
color click on the appearances go to any
and dark and in the dark mode
let's click on show color panel and
instead of this dark maroon i'm going to
use this
strawberry which is a little brighter a
little easier to see in dark mode
i'm going to just stop the preview press
play on the simulator again
and when it builds it should be in dark
mode already but
but the color should be our new dark
mode colors so
in dark mode i have this brighter purple
which i think looks a little bit better
and the secondary accent color is this
brighter pink which actually looks
awesome
and now our colors are dynamic so if we
switch back to light mode we're going to
use that those starting colors and if we
go back to dark mode
we're going to use these new colors so
this
this is looking pretty cool let's go to
the add tab to make sure that it looks
good as well
and there's only one issue i see here
and it's that the placeholder in
the dark mode has changed colors so we
can't see
the text right here that normally says
uh add something here or whatever we put
as the placeholder
so let's just customize the background
color on this really quickly
so i'm going to jump into the add view
so the background right now is this
color literal that we added
but let's use a dynamic color that will
change
and if you follow my swifty by boot camp
you are also aware of some of the ui
colors that we can import into swift ui
and there are some ui colors that are
dynamic
like the primary and secondary colors
like this text up here
so we're going to use one of those
instead of using this color literal so
let's just delete this color literal
delete this on the background and i'm
going to call color
open the parentheses and i'm going to
type a ui color
dot and then there's a bunch of ui
colors that we can
use here we have our regular colors as
well as if we start typing in a system
we'll see there's a bunch of system
colors as well and we're going to look
for the
secondary system background
and all these system colors are
automatically dynamic so they will
change between light and dark mode
and now if we use the secondary system
background i think it's going to look a
little better
let's press uh play on the simulator one
more time
see what it looks like
and i'm gonna go to the ad this looks
good i like this nice
kind of grayish background we can see
type something here still
if we type it should say hello it's
white text that looks good
uh let's switch back to light mode
just to make sure this new color still
looks good in light mode
and it does we have black text we have
our gray background and it's looking
great
we're running this on a simulator i
enjoy doing it on a simulator once we're
like kind of finished with
our app but just so you guys do know we
can always
open up the canvas
and click resume on the canvas
and the canvas right now is in light
mode but we can change it by clicking
this little computer thing here
and changing the color scheme to dark
mode
so automatically change our canvas to
dark mode if we scroll
down on this project to the preview
section
we can see that the preferred color
scheme is now dark and if we really
wanted to we could add
two different simulators here we could
add a group
open the brackets and i'm going to cut
this navigation view and just paste it
twice
inside this group and this and the first
one i'll make a light
and second one i'll make dark and now we
can see
back to back we have our light mode on
the right and if i scroll down we have
our dark mode
so if we didn't want to run the
simulator and we had a lot of things to
edit i would do it like this in our
preview
where we can check light and dark mode
really quickly
just for this screen but of course we
didn't have much to do
so using the simulator was fine it was
easier
and i think we're done with light and
dark mode
all right so this all looks great let's
put it back in a dark mode just because
we spent the entire
video in light mode and dark mode looks
really cool i think
i think this looks awesome while we're
here let's check this out by running it
on
landscape so we can just click this
little button here
to rotate the device and automatically
we are rotated
there wasn't much we had to do here um
because when we formatted our screens we
used things like
max with we didn't set specific widths
and our device automatically adjusted to
be horizontal
one thing i do want to change is that
this whole no items area
looks like it's maybe a little bit too
wide for my liking
so let's just limit the width on this no
items area
so i'm going to open up the no items
view
and maybe on the v stack
yeah on the v stack right before the
multi-line text alignment let's just do
dot frame and let's give it a max width
of maybe uh 400 i think would be good
so when the device is in a portrait mode
the width is about 350 or something like
that and
when it's in landscape obviously this is
much wider
but by setting a max width we can always
just limit it
when it is landscape or when it is on a
larger device as well
so if i press play one more time
run it on this horizontal it should be a
little bit in now and this looks a
little bit better
let's add an item make sure it looks
good we'll say
new item save and our new
item shows up let's do one more another
one
save this is looking good it's all
working we can go into edit mode
and i don't see any other issues here so
this is looking good on
landscape let's put it back to
portrait
i'm going to close this simulator
because it looks good on the iphone and
the last thing i want to do in this
video is check it on the ipad
let's open up the ipad so i'm going to
change so i'm going to change the
simulator up here from iphone 12
and i'm going to pick the iphone ipad
pro 12.9 inch
because it is the biggest so it will
probably better
test on that one and let's run the
simulator one more time
i'm going to pause the video quick
because uh the fan is going crazy so
i'll be right back
so with the ipad pro selected let's
press
run on the simulator i don't think
there's going to be much that we have to
do here
it should open up a new simulator let's
do it in portrait mode first
and when it loads uh
we do have one little issue here because
it did finish loading and we can't see
anything and if i click on the back
button
it looks like the navigation view is
adding
our navigation on the left side and this
is because on
ipads and larger devices the navigation
view has a different
style by default and that style has this
sidebar so we could have kind of tabs
here and when we click these tabs it can
open up other screens
and we could still have that tab bar on
the left side
so this is a really cool ipad feature
but it does not look good for what we're
doing here of course
so this is really easy to fix we're
gonna jump into our
to-do list app.swift file which is where
we have our navigation view
and on the navigation view we're just
gonna very simply add dot
navigation view style
and then we're gonna start typing in
navigation view
style and here you can see a couple of
the different styles
and you can play around with these on
your own time but
stack navigation view style is the
standard style where it's just one
screen in front of the other
so that's what we want we're gonna do
stack navigation view style
open and close the parentheses and let's
run it one more time on the ipad
and you will now see our app the way we
wanted to see it
and we have our first screen and we
click add something we go to our second
screen
this all looks good i can type in hello
let's add something this looks good to
me
and one thing you'll probably notice is
that our no items view
is still limited with that max width so
instead of going to the full screen
of the app because we added that
that max width a couple minutes ago this
now
also is max width on our ipad as well
which looks great
let's lastly just rotate it horizontally
make sure it still looks good and it
does look good to me
and that's pretty much it for this video
we didn't do too much obviously because
our app
is so simple but we made sure it looks
good in light and dark mode we adjusted
some of the colors for dark mode
we checked out our app in landscape as
well as portrait in case the user wants
to turn their device
and then we checked it on ipad just to
make sure it still looks good
we updated the navigation view so that
it's the correct style
and now our app is pretty much ready to
go
so thank you guys for watching we have
one more quick video before we finish
this app but it's looking great you guys
are doing awesome
thank you for watching as always i'm
nick this is swiffle thinking
and i'll see you in the next video
you
Weitere ähnliche Videos ansehen
Build Todo List in SwiftUI with MVVM architecture | Todo List #0
Obsidian-Excalidraw 1.8.21 - QoL Improvements: Dynamic Styling and Color Inversion
Save and persist data with UserDefaults | Todo List #4
New apk without Activation for play games with keyboard and mouse in mobile like Computer |free fire
User Experience and Animations in SwiftUI app | Todo List #5
Adding an App Icon and Launch Screen to SwiftUI | Todo List #7
5.0 / 5 (0 votes)