Blue Highlighting / Focus Ring on Catalyst App

前端 未结 6 1607
夕颜
夕颜 2020-12-29 11:52

I\'m currently in the process of porting my iOS app to macOS using Project Catalyst.

All of my text fields, text views and table views have a blue outline when activ

相关标签:
6条回答
  • 2020-12-29 11:57

    There is a private method _setFocusRingType: that appears to match the NSView API. I was able to use that to eliminate the focus ring, though this may not pass app review.

    Use this at your own risk:

    SEL selector = NSSelectorFromString(@"_setFocusRingType:");
    NSMethodSignature *signature = [self.textView methodSignatureForSelector:selector];
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
    [invocation setSelector:selector];
    NSUInteger arg = 1; // NSFocusRingTypeNone
    [invocation setArgument:&arg atIndex:2];
    [invocation invokeWithTarget:self.textView];
    

    Hopefully we get a real solution from Apple.

    0 讨论(0)
  • 2020-12-29 12:07

    This can also be done without any code in Interface Builder for specific buttons, if that fits your needs.

    In the identity inspector, just set the user-defined run-time attribute to 1 like so:

    0 讨论(0)
  • 2020-12-29 12:10

    Please don't do this - this is a focus indicator for accessibility and is important for keyboard-only users.

    0 讨论(0)
  • 2020-12-29 12:11

    In swift you can do

    
    extension UITextView {
        #if targetEnvironment(macCatalyst)
        @objc(_focusRingType)
        var focusRingType: UInt {
            return 1 //NSFocusRingTypeNone
        }
        #endif
    }
    
    
    0 讨论(0)
  • 2020-12-29 12:11

    It helps to disable focus ring in all "view" classes in Catalyst

    extension UIView {
        #if targetEnvironment(macCatalyst)
        @objc(_focusRingType)
        var focusRingType: UInt {
            return 1 //NSFocusRingTypeNone
        }
        #endif
    }
    
    0 讨论(0)
  • 2020-12-29 12:22

    A slight improvement to Amerino's answer for greater flexibility and use in Storyboards:

    @IBDesignable
    class UITextViewCS: UITextView {
        @IBInspectable
        public var focusRing: UInt = 1 // 0-default, 1-None, 2-Exterior
    
        #if targetEnvironment(macCatalyst)
        @objc(_focusRingType)
        var focusRingType: UInt {
            guard [0, 1, 2].contains(focusRing) else { return 0 }
            return focusRing
        }
        #endif
    }
    
    0 讨论(0)
提交回复
热议问题