洞察探索open banking如何通过小程序容器技术助力金融企业实现数据安全和数字化转型
721
2022-10-26
在SwiftUI中实现在图像上组合文本的应用程序
MemeMaker
MemeMaker is a little app using SwiftUI that shows a few things:
Main list uses a generic type constrained to View to pass destination view into row
Now has three examples:
Overlay
Uses the overlay modifier to overlay the text on top of the image. Probably the cleanest solution.
ZStacks
The original example using nested zstacks to pin text to top and bottom of image
Text Gone Wild
What happens when the text is allowed to spread out as far as it canShadow is added to all text in this example so it can be seen
All Example Memes also show
Using a named font instead of one of the semantic font stylesAdding a shadow to Text and creating a non-named color
It was also used to create this meme, which I found amusing: https://twitter.com/jamesdempsey/status/1138491138740895744
Notes
This is a not-particularly-functional app created by someone on their first day of using a new technology.
You can’t edit the text except by editing the codeYou can't different image unless add other images to the project.You can’t export or share the meme.
The app composes some text over an image in a few different ways and then you can take a screenshot of the result to share if you want to.
Caveats
The image is too wide for the screen, so the ends are clipped.
There should be a more elegant way to pin text at the top and bottom of the image than using two ZStacks. UPDATE: There is! Check out the Overlay example in the app.
Clearly, I need to learn more about having views size themselves in SwiftUI.
I also need to brush up on my generics and protocols. I know I need the type-erased AnyView type to keep from hardcoding destination views in the row view, but I couldn't explain to you very clearly why. UPDATE: In fact, I should really only be using AnyView as a last resort. Based on that feedback from Matt Ricketson (@ricketson_), I've updated to use generics.
So, I'm putting this out there as a starting point if you want to check it out or play with it. Feel free to download or fork it and play with it on your own. If you discover better techniques for any of it, I'd love it if you'd let me know. I'm @jamesdempsey at Micro.blog and Twitter.
You can read more about my initial experiences with SwiftUI at jamesdempsey-.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~