Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.

All subtopics
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

TextKit2 : - The text inserted between the attributedText(Paragraph) doesn't inherit the attributes of existing text
I have added an custom attribute for a paragraph using the below method textStorage.addAttribute(.customCase, value: "checkList", range: paragraphRange) When I insert some text in between the text which contains the custom attribute, that text is not inheriting/propagating the custom attribute of existing paragraph text Old Text : - This is a test New Text : - This is "some new" a test The inserted part is not getting the custom attribute of the old text, Can I know why it's happening, Is it some textKit2's behaviour.
0
0
410
Dec ’24
UIWritingToolsCoordinator.Context Lifetime?
What is the lifetime of a UIWritingToolsCoordinator.Context object? The UIWritingToolsCoordinator.Delegate API expects you to maintain a reference to the context identifiers you create in writingToolsCoordinator(:contextsFor:) to be able to return them in writingToolsCoordinator(:rangeInContextWithIdentifierFor:). At some point, you need to release these references. Can you, for example, assume that the context will not be referenced after writingToolsCoordinator(_:willChangeToState:) is called with a state of .inactive?
Topic: UI Frameworks SubTopic: UIKit
0
1
283
Dec ’24
Adding a Label with UIImage and Text to the TabSection Header in tvOS 18+
I've been trying to add a header to the tabSection of the tabview in tvos 18+ . init( @TabContentBuilder<SelectionValue> content: () -> Content, @ViewBuilder header: () -> Header ) where Header : View, Footer == EmptyView Here the ehader clearly conforms to View but i cant quite fit the label with uiimage as the icon into this. This Label when i add it to any other view, the image is in the specified 50 x 50 size but inside header it functions weirdly to be of a huge size. but also to note, if i simply hav an icon here, it is correct. So what is the problem here.. can someone help me? im supposed to add the user profile and name in the header. I dont think there's any other way
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
0
340
Jan ’25
iPadOS 18 App (on Apple Silicon) - Duplicate Tab Bar Appearing in Toolbar
With iPadOS 18, the UITabBar now defaults to the floating style. I successfully reverted the tab bar to its traditional style by overriding the UITabBarController's horizontalSizeClass property: self.tabBarController?.traitOverrides.horizontalSizeClass = .unspecified When I launch the app on my Mac using Apple Silicon, TWO tab bars appear: One appears at the bottom of the screen, like a traditional tab bar. The second tab bar is still embedded in the app toolbar in its floating style. Is this a bug? How do you ensure that overriding the horizontalSizeClass will remove/hide the floating tab bar when running an app on Apple Silicon? TIA! (Demonstrated on a test project)
0
0
456
Jan ’25
侧划返回卡死
xcode16,iphone16,iOS 自定义navigationItemLeftBar,设置 navigationController?.interactivePopGestureRecognizer?.delegate = self,侧划返回一半,点击屏幕,界面卡死。 18系统之前的手机,或者非iphone16的手机没有问题。
0
0
376
Nov ’24
SwiftUI .fileImporter does not react to isPresented change.
I made a ImagePicker which worked pretty well. But when app get bigger it stops. Does not react to change isPresented value. As far I know I changed nothing around this part of an App. Also same thing happened in different place, another kind of picker. print ("HELL'o") never prints. Silence. struct ImagePicker: View { @Binding var imageSource: ImageSource @State var showFileImporter: Bool = false @EnvironmentObject var manager: Manager var body: some View { VStack { .... Button(action: { print("before", showFileImporter) showFileImporter = true print("after", showFileImporter) }, label: { Text("open Image") }) .buttonStyle(.borderless) .controlSize(.mini) }.fileImporter(isPresented: $showFileImporter, allowedContentTypes: [.png, .jpeg, .tiff], onCompletion: { result in print ("HELL'o") // Never prints switch result { case let .success(url): guard let _ = try? Data(contentsOf: url) else { return } .... case let .failure(error): print(error) } }) } } Does anybody have an idea what happened? I suspect some settings in completely different palce or bug or computer does not like me.
0
0
309
Dec ’24
SwiftUI Canvas Text - scale to fill rectangle
How do I draw a single line of text in a SwiftUI Canvas, scaled to fill a given rectangle? Example: Canvas { context, size in let r = CGRect(origin: CGPointZero, size: size); // Whole canvas let t = Text("Hello World"); context.draw(t, in: r); } Outside of Canvas I'd add .minimumScaleFactor(0) .lineLimit(1), and I guess set a large default font size, and I'd get the result I want. But inside Canvas, .minimumScaleFactor and .lineLimit don't seem to be available; they return some View, not Text, which can't be used in context.draw. (Is there a trick to make that work?) I have written the following to do this, but I think there must be an easier way to achieve this! Suggestions? extension GraphicsContext { mutating func draw_text_in_rect(string: String, rect: CGRect) { let text = Text(string) .font(.system(size: 25)); // The font size used here does matter, because e.g. letter spacing // varies with the font size. let resolved = resolve(text); let text_size = resolved.measure(in: CGSize(width: CGFloat.infinity, height: CGFloat.infinity)); let text_aspect = text_size.width / text_size.height; let fit_size = CGSize(width: min(rect.size.width, rect.size.height*text_aspect), height: min(rect.size.height, rect.size.width/text_aspect)); let fit_rect = CGRect(x: rect.origin.x + (rect.size.width-fit_size.width)/2, y: rect.origin.y + (rect.size.height-fit_size.height)/2, width: fit_size.width, height: fit_size.height); let scale = fit_size.width / text_size.width; // For debug: // var p = Path(); // p.addRect(fit_rect); // stroke(p, with: GraphicsContext.Shading.color(.red), lineWidth: 1); translateBy(x: fit_rect.minX, y: fit_rect.minY); scaleBy(x:scale, y:scale); draw(resolved, at: CGPointZero, anchor: UnitPoint.topLeading); transform = CGAffineTransformIdentity; } };
0
0
351
Jan ’25
How to override NSWindow in a pure SwiftUI Application
So I am looking to use a custom NSWindow application (so I can implement some enhanced resizing/dragging behavior which is only possible overriding NSWindow). The problem is my whole application is currently SwiftUI-based (see the project here: https://github.com/msdrigg/Roam/blob/50a2a641aa5f2fccb4382e14dbb410c1679d8b0c/Roam/RoamApp.swift). I know there is a way to make this work by dropping my @main SwiftUI app and replacing it with a SwiftUI root view hosted in a standard AppKit root app, but that feels like I'm going backwards. Is there another way to get access (and override) the root NSWindow for a SwiftUI app?
0
0
269
Mar ’25
NSHostingController menu not activated
I'm attempting to write a macOS version of https://stackoverflow.com/a/74935849/2178159. From my understanding, I should be able to set the menu property of an NSResponder and it will automatically show on right click. I've tried a couple things: A: set menu on an NSHostingController's view - when I do this and right or ctrl click, nothing happens. B: set menu on NSHostingController directly - when I do this I get a crash Abstract method -[NSResponder setMenu:] called from class _TtGC7SwiftUI19NSHostingControllerGVS_21_ViewModifier_...__. Subclasses must override C: manually call NSMenu.popup in a custom subclasses of NSHostingController or NSView's rightMouseDown method - nothing happens. extension View { func contextMenu(menu: NSMenu) -> some View { modifier(ContextMenuViewModifier(menu: menu)) } } struct ContextMenuViewModifier: ViewModifier { let menu: NSMenu func body(content: Content) -> some View { Interaction_UI( view: { content }, menu: menu ) .fixedSize() } } private struct Interaction_UI<Content: View>: NSViewRepresentable { typealias NSViewType = NSView @ViewBuilder var view: Content let menu: NSMenu func makeNSView(context: Context) -> NSView { let v = NSHostingController(rootView: view) // option A - no effect v.view.menu = menu // option B - crash v.menu = menu return v.view } func updateNSView(_ nsView: NSViewType, context: Context) { // part of option A nsView.menu = menu } }
0
0
225
Mar ’25
CoreAutoLayout -[NSISEngine positiveErrorVarForBrokenConstraintWithMarker:errorVar:]
My App always encounter with CoreAutoLayout invade My SnapKit layout constraint as follow: popBgView.snp.makeConstraints { make in make.centerY.equalToSuperview() make.leading.equalTo(assistantTeacherView.snp.trailing).offset(.isiPad ? -50 : -40) if TTLGlobalConstants.isCompactScreen320 { make.width.lessThanOrEqualTo(300) } else { let widthRatio = .isiPad ? 494.0 / 1024.0 : 434.0 / 812.0 make.width.lessThanOrEqualTo(TTLGlobalConstants.screenWidth * widthRatio) } bubbleViewRightConstraint = make.trailing.equalToSuperview().constraint } ..... popBgView.addSubview(functionView) msgLabel.snp.remakeConstraints { make in make.leading.equalToSuperview().inset(Metric.msgLabelHorizantalInset) make.centerY.equalToSuperview() make.trailing.lessThanOrEqualToSuperview().inset(Metric.msgLabelHorizantalInset) make.top.equalTo(Metric.msgLabelVerticalInset) } functionView.snp.makeConstraints { make in make.leading.equalTo(msgLabel.snp.trailing).offset(Metric.msgLabelFunctionSpacing) make.centerY.equalToSuperview() make.trailing.equalToSuperview().offset(-Metric.msgLabelHorizantalInset) } msgLabel and functionView superview is popBgView However, when I try remove from superview for functionView, There is low probability crash: OS Version: iOS 16.1.1 (20B101) Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: SEGV_NOOP Crashed Thread: 0 Application Specific Information: Exception 1, Code 1, Subcode 14967683541490370463 > KERN_INVALID_ADDRESS at 0xcfb7e4e0f8fe879f. Thread 0 Crashed: 0 CoreAutoLayout 0x382555f44 -[NSISEngine positiveErrorVarForBrokenConstraintWithMarker:errorVar:] 1 CoreAutoLayout 0x382555e9c -[NSISEngine positiveErrorVarForBrokenConstraintWithMarker:errorVar:] 2 CoreAutoLayout 0x3825557e4 -[NSISEngine removeConstraintWithMarker:] 3 CoreAutoLayout 0x382555198 -[NSLayoutConstraint _removeFromEngine:] 4 UIKitCore 0x34d87961c __57-[UIView _switchToLayoutEngine:]_block_invoke 5 CoreAutoLayout 0x382556e8c -[NSISEngine withBehaviors:performModifications:] 6 UIKitCore 0x34d8a1c38 -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] 7 UIKitCore 0x34d7f01b0 __57-[UIView _switchToLayoutEngine:]_block_invoke_2 8 UIKitCore 0x34d879770 __57-[UIView _switchToLayoutEngine:]_block_invoke 9 CoreAutoLayout 0x382556e8c -[NSISEngine withBehaviors:performModifications:] 10 UIKitCore 0x34d8a1c38 -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] 11 UIKitCore 0x34d8a1848 __45-[UIView _postMovedFromSuperview:]_block_invoke 12 UIKitCore 0x34e7ff8d0 -[UIView _postMovedFromSuperview:] 13 UIKitCore 0x34d85e3c8 __UIViewWasRemovedFromSuperview 14 UIKitCore 0x34d85b1a4 -[UIView(Hierarchy) removeFromSuperview] 15 Collie-iPad 0x203001550 [inlined] InClassAssistantView.functionView.didset (InClassAssistantView.swift:105)
Topic: UI Frameworks SubTopic: UIKit
0
0
235
Jan ’25
XCode breakpoint possible for "Publishing changes from within view updates is not allowed, this will cause undefined behavior."?
Dear Sirs, I'm searching for the most straightforward way to identify the root of a "Publishing changes from within view updates is not allowed, this will cause undefined behavior." warning. It is a complex SwiftUI project and I think there should be a better way than just try and error with disabling/removing and enabling/adding different screen elements to check if the warning still is shown. I tried to set a symbolic breakpoint for "os_log" in my XCode project and indeed this is triggered right before the warning appears but the callstack doesn't give me a direct hint to the part of my code which causes this warning. What would be the most direct way and is there something like an exception handler in such cases? Thanks and best regards, Johannes
0
0
452
Jan ’25
AppIntents - Choosing a default Measurement<UnitMass> for body weight based on locale
Here’s a clearer and more concise version of your question: I’m creating an AppIntent to allow users to log their body weight. My intent includes a @Parameter defined as: @Parameter( title: "Weight", description: "Current Weight", defaultUnit: .pounds, supportsNegativeNumbers: false ) var weight: Measurement<UnitMass> This works but doesn’t respect the user’s Locale and its measurementSystem. When I add defaultUnitAdjustForLocale: true to the @Parameter macro, the default always switches to kilograms, regardless of the locale. How can I correctly set the default unit to match the user’s locale for the purpose of entering a users body weight?
0
0
359
Jan ’25
Full Screen Tile: Left of Screen
I want to use Objective C language to implement a button, click the button to achieve the function of Menu Bar - Full Screen Tile - Left of Screen. What should I do? I couldn't find the relevant API.
Topic: UI Frameworks SubTopic: AppKit
0
0
353
Dec ’24
Live Acitivities - ProgressView problem
Hello i ve implemented progressview and updating the state via push notification. the progress view wants closedrange which i followed but whenever i get update, the progress value resets to beginning my range is like : Date.now..endDate but i dont get it, lets assume that i get the date from database and initialized already then how the code will understand that what progress value will be as current ? it has to be something like i suppose : startDate..Date.now..endDate thanks
0
0
414
Nov ’24