Post

Replies

Boosts

Views

Activity

Reply to Trying to get UIBarButtonItem custom view to change color within iOS 26 Liquid Glass like native UIBarButtonItem
This may well be related to a bug I'm also seeing in iOS 26. In beta 4, many controls were messed up in dark mode, so that they didn't adapt to a dark appearance at all, including UIBarButtonItems with a customView. There have been some improvements in beta 5, but some controls now have a disabled appearance in dark mode when they are in fact enabled. UIBarButtonItems with a customView are one of the controls affected. I'm seeing this in my own app, and I can easily reproduce this with a UIBarButtonItem that uses a UISegmentedControl as its customView. Here it is in light mode: (Only the link button should be disabled, so all is as expected in light mode.) And in dark mode (or in light mode but against a dark background): As you can see, the segmented control now looks disabled when it isn't. And this is set up using the segmented control directly as the custom view (i.e. UIBarButtonItem(customView: segmentedControl)). I've reported this as FB19431646. The issue may be more general, as nav bar titles in sidebars and inspectors also appear pale grey and disabled (FB19431807). Original report for dark mode issues in beta 4: FB19023069.
Topic: UI Frameworks SubTopic: UIKit Tags:
4w
Reply to Positioning an image
You should generally add the constraints in your view controller code, where you have access to both views., right after calling addSubview(:). Or if you really want the code in your image view for some reason you could create a method on your image view that takes the view as a parameter (e.g. addToView( view: uIView)) and call that from the view controller.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jul ’25
Reply to Positioning an image
These lines are your problem: self.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true self.topAnchor.constraint(equalTo: self.centerYAnchor).isActive = true You‘re setting self.centerXAnchor to equal itself, which will do nothing, and self.topAnchor to equal self.centerYAnchor, which is impossible. Instead, you want to set self.centerXAnchor to equal the superview’s centerXAnchor and the same for the Y anchor. (In your case the superview will be the view controller’s view.) For a specific position rather than centred, you’ll want to use constraints lining the image view up with the leading/top/trailing/bottom edges of the superview with a constant depending on your needs.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jul ’25
Reply to iOS 26 UISplitViewController in dark mode appearance.
I've also filed a bug report on this just now (#FB19023069). I was trying to work out why a UILabel set as the subview of a glass UIVisualEffectView's content view wasn't adapting to dark mode (not in a Split View), when I realised it wasn't alone. Here's a screenshot of the sample app I sent to Apple: Light mode: So far, I've noticed the following controls are affected: Primary and inspector nav bar titles in a Split View (but not the secondary title). The toggle sidebar button (but not always). Bar button items in the nav bar with isEnabled set to false. Bar button items containing custom views (at least containing a segmented control, such as in my screenshot). Labels inside a UIVisualEffectView using the glass effect. No doubt there's more. Even setting segmentedControl.overrideUserInterfaceStyle = .dark on the segmented control in the custom nav bar item didn't help. It is very strange that Apple's own apps aren't affected.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jul ’25
Reply to Set edge effect style in AppKit
It's strongly implied in the video "Build an AppKit app with the new design": The scroll edge effect is applied automatically underneath toolbar items, title bar accessories, and… split item accessories. I've filed feedback asking for a property to control it programmatically too though. At the moment the automatic detection isn't reliable - there are easily reproducible cases where you get blurring at the top of a scroll view ("soft" effect) when it should be a hard effect (I've filed a couple of bug reports on this). Of course macOS 26 is still in early beta so fingers crossed these bugs will be fixed, but it would be good to have some manual control in case there are edge cases that automatic detection still misses - especially since there are properties for this in both SwiftUI and UIKit, with only AppKit lacking.
Topic: UI Frameworks SubTopic: AppKit Tags:
Jul ’25
Reply to Circular Reference Error in Xcode 26
I tried reproducing this but couldn’t. Having seen the error myself, I could reproduce it as follows: Paste the three structs from the op's original post into a Swift file in a new app project. Change "Decodable" for each to "Codable" (I couldn't reproduce it for "Decodable" only for some reason). Make sure that strict concurrency checking is set to "Complete" and "MainActor" is set as the default actor isolation for the project. When I do this, I see a "Circular reference" error with several "Through reference here" comments that don't make much sense. There seem to be two possible fixes depending on how the struct is intended to be used: Explicitly set the struct as "nonisolated" (which prior to the change in default actor isolation would have been the default): nonisolated struct FriendListResponse: Codable Force the conformance to @MainActor: struct FriendListResponse: @MainActor Codable (Note that the second solution will break if you use custom codingKeys, however, even if you try to force the conformance on that to @MainActor - not sure why.) I hasten to add that my knowledge of Swift 6 and concurrency is wanting - I'm only starting to explore migration from Swift 5 to Swift 6 and understanding the errors involved, so apologies to the op if this is unhelpful.
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’25
Reply to UITextView with large `textContainerInset` scrolls upwards when selecting text
This bug has been around for a long time. I first reported it to Apple back in 2016 (radar ID 25220931; updated #FB6001878 last year). In my app, I make it so that you can have a large gap below the text you are writing, so that the text is not always at the bottom of the editor (like in Xcode). I was initially using a large bottom textContainerInset to achieve this, but this triggered the selection scrolling bug you describe. My workaround is to leave the bottom textContainerInset alone and to instead increase the contentSize height in a UITextView subclass. (I add the extra height whenever the contentSize is set in the subclass override.) This really only works for adding space below, though. To add space above, as you want, you'd need to mess with contentInset, but doing so causes the same selection scrolling problem as adjusting the textContainerInset so unfortunately gets you nowhere. In your situation I think the only solution is to push the entire top of the text view down to make space for the comment, even though that might not be ideal, as presumably you wanted the text view visible and scrollable beneath the comment.
Topic: UI Frameworks SubTopic: UIKit
Jun ’24
Reply to What is the designated way to do custom background drawing in TextKit 2 when using UITextView/NSTextView?
Overriding NSTextLayoutFragment.draw(at:in:) in an NSTextLayoutFragment subclass provided by the NSTextLayoutManagerDelegate is indeed the designated way of doing custom drawing now. However, note that it still doesn't have quite the same effect as NSLayoutManager.drawBackground(forGlyphRange:at:). While you can draw behind the text by doing your custom drawing before calling super.draw(at: point, in: context), all custom drawing in NSTextLayoutFragment is still done above text text view's selection (in NSTextView anyway). In NSLayoutManager, drawing done in drawBackground(forGlyphRange:at:) was done beneath the text selection, which could be useful for some elements. There seems to be no way of doing the same in TextKit 2 just yet. (I filed this as #FB10159592 but received a fairly standard dismissive reply). You can also do custom drawing in NSTextView's drawBackround(in:), but that's more awkward because calculating the visible ranges is expensive. For custom interaction, I suppose it depends on what you're trying to do. You could do it in a text view subclass and use NSTextLayoutManager's various methods to get the frames of the text you need. For instance, I allow live image resizing in an NSTextView, and draw resizing handles over image text attachments. For that I can use NSTextLayoutManager's layoutFragment(for: point) in mouseDown(_:), converting the point from text view to text container coordinates, and I can then get the image frame using NSTextLayoutFragment.frameForTextAttachment(at:), and add a new sublayer to the text view to draw my resizing handles. There are a couple of gotchas here, though: Because NSTextView (and presumably UITextView) in TextKit 2 does all of its drawing using layers, you have to set the z position of any new sublayer you add to something high (e.g.FLT_MAX). The coordinate system used for TextKit 2 is so far undocumented, and seems pretty strange. NSTextLayoutFragment.layoutFragmentFrame is straightforward, being in text container coordinates, and NSTextLayoutFragment.renderingSurfaceBounds is relative to that (although the docs say its coordinates are flipped compared to layoutFragmentFrame, when they don't seem to be). However, both NSLayoutFragment.frameForTextAttachment(at:) and NSTextLineFragment.typographicBounds seem to be relative to NSTextLayoutFragment.layoutFragmentFrame vertically, but relative to the text container horizontally. (And there are also some issues with the frames being narrower than you'd expect when using overlay scroll bars.) I'm not sure how helpful that is to what you want to do.
Topic: UI Frameworks SubTopic: General Tags:
Jun ’22
Reply to How to access the textContentStorage of UITextView in iOS 16?
It is a little strange that UITextView doesn't have a convenience property for this. However, you can still access it easily enough via the textLayoutManager's .textContentManager property (NSTextContentStorage being the concrete subclass of NSTextContentManager used by NS/UITextView). And of course you could create an extension to UITextView to add the .textContentStorage property yourself: extension UITextView {     var textContentStorage: NSTextContentStorage? {         return textLayoutManager?.textContentManager as? NSTextContentStorage     } } Hopefully Apple will add this, though, as it would be useful. (I've filed an enhancement request: #FB10376167.)
Topic: App & System Services SubTopic: General Tags:
Jun ’22
Reply to Where is the sample code for TextKitAndTextViewSampleApp?
Here you go: https://developer.apple.com/documentation/uikit/textkit/enriching_your_text_in_text_views There's not much meat in there, unfortunately, and the lists are very buggy (on macOS, try clicking at the end of a line). It also seems there's a lot of stuff not yet available in the first Ventura/Xcode 14 beta. For instance, the NS/UITextView constructor init(usingTextLayoutManager:) seems to be missing.
Topic: App & System Services SubTopic: General Tags:
Jun ’22