SwiftUI | 🚀 | Frontend Framework library
kandi X-RAY | SwiftUI Summary
kandi X-RAY | SwiftUI Summary
This article refers to SwiftUI apple example and records the results of the exploration here, I hope to be helpful to you. For the content described in this article, by default you have some experience based on Swift language development, so it will not describe every detail in detail; if you have doubts about Swift syntax, you can learn Swift Grammar. When learning and using SwiftUI, if you have any questions, you can join the SwiftUI QQ Group: 18552966 to discuss communication.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of SwiftUI
SwiftUI Key Features
SwiftUI Examples and Code Snippets
Community Discussions
Trending Discussions on SwiftUI
QUESTION
I'm trying to implement a PHPickerViewController
using SwiftUI and The Composable Architecture. (Not that I think that's particularly relevant but it might explain why some of my code is like it is).
I've been playing around with this to try and work it out. I created a little sample Project on GitHub which removes The Composable Architecture and keeps the UI super simple.
https://github.com/oliverfoggin/BrokenImagePickers/tree/main
It looks like iOS 15 is breaking on both the UIImagePickerViewController and the PHPickerViewController. (Which makes sense as they both use the same UI under the hood).
I guess the nest step is to determine if the same error occurs when using them in a UIKit app.
My codeMy code is fairly straight forward. It's pretty much just a reimplementation of the same feature that uses UIImagePickerViewController
but I wanted to try with the newer APIs.
My code looks like this...
...ANSWER
Answered 2021-Sep-26 at 14:32Well.. this seems to be an iOS bug.
I have cerated a sample project here that shows the bug... https://github.com/oliverfoggin/BrokenImagePickers
And a replica project here written with UIKit that does not... https://github.com/oliverfoggin/UIKit-Image-Pickers
I tried to take a screen recording of this happening but it appears that if any screen recording is happening (whether on device or via QuickTime on the Mac) this suppresses the bug from happening.
I have filed a radar with Apple and sent them both projects to have a look at and LOTS of detail around what's happening. I'll keep this updated with any progress on that.
Hacky workaroundAfter a bit of further investigation I found that you can start with SwiftUI and then present a PHPickerViewController without this crash happening.
From SwiftUI if you present a UIViewControllerRepresentable... and then from there if you present the PHPickerViewController it will not crash.
So I came up with a (very tacky) workaround that avoids this crash.
I first create a UIViewController
subclass that I use like a wrapper.
QUESTION
I am trying to display rich links in a SwiftUI List and no matter what I try, I can't seem to be able to change the size of the link view (UIViewRepresentable) on screen.
Is there a minimum size for a particular link? And how can I get it. Adding .aspectRatio and clipped() will respect size but the link is heavily clipped. Not sure why the link will not adjust aspectRatio to fit view.
Some of the following code is sourced from the following tutorial: https://www.appcoda.com/linkpresentation-framework/
I am using the following UIViewRepresentable for the LinkView:
...ANSWER
Answered 2021-Dec-29 at 13:24The solution that worked for me was subclassing the linkView overriding the intrinsic content size. Thanks to user1046037's comment, using super.intrinsicContentSize.height will enable it to work dynamically.
QUESTION
I've tried to Google for the answer but all I find are how to accept drop from other apps and drag and drop in a single app, also mostly iOS focus and not many macOS related resources.
I writing a macOS toolbar app that I'm trying to implement drag and drop for the image the app create programatically and only in memory as NSImage. To allow the image to be draggable, I've implemented the a DraggableImage struct to be used in place of the Image
view in the SwiftUI view:
ANSWER
Answered 2021-Oct-29 at 08:48You need to export file URL
instead of Data
, so this file can be copied by MacOS.
Basic example:
QUESTION
On iOS 15, the UIHostingController
is adding some weird extra padding to its hosting SwiftUI view (_UIHostingView
).
See screenshot below (Blue = extra space, Red = actual view’s):
Does anyone know why this happens?
I've reported this bug, Apple folks: FB9641883
PD: I have a working project reproducing the issue which I attached to the Feedback Assistant issue. If anyone wants it I can upload it too.
...ANSWER
Answered 2021-Sep-30 at 08:50I’ve tried to find why is this happening without luck. The only thing I’ve found to fix it is setting a height constraint to its intrinsic content size in a subclass of UIHostingController
:
QUESTION
I am using custom font (Catamaran) and it seems like it has big space between lines in it. For example I have this code:
...ANSWER
Answered 2021-Jul-08 at 10:32SwiftUI might use values of hhea
(Horizontal header table) to set the Text
box height. In your case, Catamaran has an ascender of 1100 and a descender of 540. The box height will be calculated as the sum of these two values: 540 + 1100 = 1640. And the UPM (Units per Em) of the font is default 1000. Which means in SwiftUI, when .font(.custom(..., size: 1000))
is set, each line of Text()
will have a frame whose height is 1640.
In terms of .lineSpacing()
, SwiftUI doesn't set the value for spacing between baselines, but spacing between two boxes instead. If you want to have no spacing between two boxes in the example below, unfortunately setting .lineSpacing()
to -(1640-1000) = -640
is not allowed (negative values not acceptable).
UPDATE: An UIViewRepresentable
Method
However, you can use UILabel
instead to reduce line height:
QUESTION
I have been testing the async/await functionality previewed in the Swift 5.5 release, but I am unable to collect the results from an async function and display them using SwiftUI. Here is my code:
...ANSWER
Answered 2021-Jun-14 at 21:52I'm the author of the article you referenced.
As discussed in Discover concurrency in SwiftUI, views can make use of the new .task { }
and .refreshable { }
modifiers to fetch data asynchronously.
So you now have the following options to call you async code:
QUESTION
I've made some custom slider views in SwiftUI that change appearance based on hover state, but if the mouse moves out too fast (which is actually a very reasonable speed of moving a cursor), it stays in the hover state until you re-hover and re-leave the component slowly.
Is there a solution for this? The hover code is pretty standard:
...ANSWER
Answered 2021-Mar-01 at 22:49I resolved this issue today with a tracking area on an empty NSView. This is tested in a semi-complex and quickly refreshing grid view, which previously had the same behavior you pictured. About 75 views have this modifier applied in the GIF capture in this gist, most with zero border to each other.
Sugar for call siteQUESTION
I have this simple view.
...ANSWER
Answered 2021-Jan-28 at 15:59I had the very same problem. Eventually, I figured out that this happens when the project name starts with a number character, e.g. "01-test"
. Creating a new project without the digit as a first character works just fine, e.g. "test"
.
QUESTION
I have a SwiftUI app with a widget. When I run the app via Xcode (either straight to my device or on the simulator), the widget works exactly as expected.
However, when I run the app through TestFlight, the widget does appear, but it does not show any data -- it's just the empty placeholder. The widget is supposed to show an image and some text, but it shows neither.
I've seen some posts on Apple Developer forums about similar problems. One accepted answer says the following:
- Make sure that you use Xcode 12 beta 4 and iOS 14 beta 4 on your devices. Make sure that you have placeholder(in:) implemented. Make sure that you don't have placeholder(with:) because that's what the previous beta of Xcode was suggesting with autocompletion and without that you won't get your placeholder working. I think this whole problem is caused by the WidgetKit methods getting renamed but that's another story.
- As per the release notes, you need to set "Dead Code Stripping" to NO in your extension target's build settings. This is only necessary for the extension's target.
- When uploading your archive to the App Store Connect, uncheck "Include bitcode for iOS content".
- Delete your old build from a device when installing a new beta.
I've implemented these suggestions, to no avail.
Here's my code for the widget. It first fetches game data via CloudKit, then creates a timeline:
...ANSWER
Answered 2021-May-22 at 18:23Did you try to deploy the cloudkit container to the production? You can find it on the CloudKit Dashboard.
QUESTION
I have this view to show text tags on multiple lines which I got from SwiftUI HStack with Wrap, but when I add it in a VStack the tags overlap any other view that I put below. The tags are shown properly but the height of the view itself is not calculated inside the VStack. How can I make this view use the height of is content?
...ANSWER
Answered 2020-May-30 at 13:38I just managed to solve this by moving the GeometryReader up to the ExampleTagsView and using platforms.first instead of last inside .alignmentGuide
Full code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SwiftUI
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page