Blue Highlighting / Focus Ring on Catalyst App
In swift you can do
extension UITextView {
#if targetEnvironment(macCatalyst)
@objc(_focusRingType)
var focusRingType: UInt {
return 1 //NSFocusRingTypeNone
}
#endif
}
The blue focus ring outside NSTextField missing?
Perhaps I did totally wrong programming, so that few people met this problem.
I found a way to solve this problem. I mentioned that all (or most of?) the graphic changes should be done in main thread in a blog. Therefore I change the "if(success)" as:
if(success){
dispatch_async(dispatch_get_main_queue()' ^{
[[self view] removeFromSuperview];
[self sendMessageToSuperview:@"Add Next View"];
});
}
Solved, the focus rings come back.
SwiftUI: Remove 'Focus Ring' Highlight Border from macOS TextField
As stated in an answer by Asperi to a similar question here, it's not (yet) possible to turn off the focus ring for a specific field using SwiftUI; however, the following workaround will disable the focus ring for all NSTextField
instances in the app:
extension NSTextField {
open override var focusRingType: NSFocusRingType {
get { .none }
set { }
}
}
If you want to replace this with your own custom focus ring within the view, the onEditingChanged
parameter can help you achieve this (see below example); however, it's unfortunately called on macOS when the user types the first letter, not when they first click on the field (which isn't ideal).
In theory, you could use the onFocusChange
closure in the focusable
modifier instead, but that doesn't appear to get called for these macOS text fields currently (as of macOS 10.15.3).
public struct SearchTextView: View {
@Binding var searchText: String
@State private var hasFocus = false
#if !os(macOS)
private var backgroundColor = Color(UIColor.secondarySystemBackground)
#else
private var backgroundColor = Color(NSColor.controlBackgroundColor)
#endif
public var body: some View {
HStack {
Spacer()
#if !os(macOS)
Image(systemName: "magnifyingglass")
#else
Image("icons.general.magnifyingGlass")
#endif
TextField("Search", text: self.$searchText, onEditingChanged: { currentlyEditing in
self.hasFocus = currentlyEditing // If the editing state has changed to be currently edited, update the view's state
})
.textFieldStyle(PlainTextFieldStyle())
.foregroundColor(.primary)
.padding(8)
Spacer()
}
.foregroundColor(.secondary)
.background(backgroundColor)
.cornerRadius(12)
.border(self.hasFocus ? Color.accentColor : Color.clear, width: self.hasFocus ? 3 : 0)
.padding()
}
public init(searchText: Binding<String>) {
self._searchText = searchText
}
}
SwiftUI: How to edit FocusRing shape or disable it?
the following code disables focusRing for all of textFields inside of file where it is located in
//Disable focusRing inside the FILE
fileprivate extension NSTextField {
override var focusRingType: NSFocusRingType {
get { .none }
set { }
}
}
OR
//Disable focusRing inside PROJECT
public extension NSTextField {
override var focusRingType: NSFocusRingType {
get { .none }
set { }
}
}
How to get a search bar into an NSToolbar in a Catalyst app?
Thanks to mmackh, the search bar can be added in just as easily as any other toolbar item. Thank all of you who looked into this.
https://github.com/mmackh/Catalyst-Helpers
Swift Example
Once you add the files to your project (and in this case your bridging header), just return this as you would any other toolbar item.
let item = NSToolbarItem_Catalyst.searchItem(withItemIdentifier: "searchBar", textDidChangeHandler: { string in
print(string)
})
How do apps like Skype show caller IDs in the native iOS recent calls list when a user isn't a contact in Swift?
Paulw11's comment was the answer to my question:
They report the name via a CXCallUpdate when they report the incoming
call. If your app isn't a voip app then you can create a callkit
directory extension github.com/paulw11/CallKitTutorial
Related Topics
How to Open File Dialog with Swiftui on Platform "Uikit for MAC"
How to Use Unsafemutablerawpointer to Fill an Array
Uisplitviewcontroller Displaymodebuttonitem()
How Is a Type-Erased Generic Wrapper Implemented
How to Restrict the Type That a Function Throws in Swift
How to Make Alphabetically Section Headers in Table View with a Mutable Data Source
How to Open/View iOS Oslogs Stored on Device
Why 'There Cannot Be More Than One Conformance, Even with Different Conditional Bounds'
Get Url to a Local File with Spm (Swift Package Manager)
How to Encode Realm's List<> Type
How to Utilize Nslock to Prevent a Function from Firing Twice
How to Get All Days in Current Week in Swift
Adding Uibarbutton Item in Swift
App Crash on Sign in (Xcode 9.3) Exc_Bad_Access (Code=1, Address=0X1)
Swift - 'Bool' Is Not a Subtype of 'Void'
Adjust Nsvisualeffectview Blur Radius and Transparency
Swiftui - Foreach Deletion Transition Always Applied to Last Item Only