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

前端 未结 8 999
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:30

    I've found something better:

    -(void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator {
        [coordinator addCoordinatedAnimations:^{
            if (self.focused) {
                self.backgroundColor = [UIColor whiteColor];
            }
            else {
                self.backgroundColor = [UIColor clearColor];
            }
        } completion:nil];
    }
    

提交回复
热议问题