How can I create a button with a background color for tvOS while still showing focus?

前端 未结 8 974
Happy的楠姐
Happy的楠姐 2021-01-02 05:02

All I want to do is add a background color to a button for all states. But I want to maintain the automatic focus shadow that you get \"for free\" when using a system button

相关标签:
8条回答
  • 2021-01-02 05:34

    You can set the background image in storyboard to an image that contains the color you would like

    0 讨论(0)
  • 2021-01-02 05:39

    You can add a shadow for your custom button like this:

    - (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
    {
        context.nextFocusedView.layer.shadowOffset = CGSizeMake(0, 10);
        context.nextFocusedView.layer.shadowOpacity = 0.6;
        context.nextFocusedView.layer.shadowRadius = 15;
        context.nextFocusedView.layer.shadowColor = [UIColor blackColor].CGColor;
        context.previouslyFocusedView.layer.shadowOpacity = 0;
    }
    
    0 讨论(0)
提交回复
热议问题