【问题标题】:Increase UIButton's touch effect radius on highlight增加 UIButton 在高亮时的触摸效果半径
【发布时间】:2013-01-23 14:20:28
【问题描述】:

在启用Shows Touch on Highlight 时,有没有办法增加 UIButton 的“发光效果”?在大多数情况下,它在 iPhone 上很好,但在 iPad 上太小了。如果不可能,任何想法如何实现所需的行为?

编辑:

基本上,我正在寻找如何将 UIButton 子类化以添加此功能。

【问题讨论】:

    标签: iphone ios ipad cocoa uibutton


    【解决方案1】:

    我会使用这样的东西: 为按钮上按下的按钮添加目标。

    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
    

    这是按下按钮时调用的方法。您可以更改 shadowRadius 以满足您的需要。

    - (void) buttonPressed:(id) sender
    {
        UIButton *button = (UIButton *) sender;
        DDLogInfo(@"%@ Button Pressed...", button.titleLabel.text);
        UIColor *color = [UIColor whiteColor];
        button.layer.shadowColor = [color CGColor];
        button.layer.shadowRadius = 20.0f;
        button.layer.shadowOpacity = 0.9;
        button.layer.shadowOffset = CGSizeZero;
        button.layer.masksToBounds = NO;
        button.backgroundColor = [UIColor whiteColor];
    }
    

    【讨论】:

    • 我正在寻找一种模仿完全相同(动画)行为的解决方案,但具有可分配的半径。如果我想同时使用阴影,您的代码也会失败。
    • 我实际上并没有使用“显示触摸突出显示”,而是在我可以调整半径的地方进行自己的突出显示。
    • 从我的解决方案中删除最后一行:button.backgroundColor = [UIColor whiteColor];
    • 这不是我想要的。同时,我能够找到一个合适的解决方案,由于隐私原因,我无法在此处发布。因此,我接受你的回答,这也足够好了。
    • @AttilaH 你找到 showtouchonHighlight 的解决方案了吗?
    【解决方案2】:

    您可以创建发光效果的图像,并在按钮突出显示时将其添加到按钮。

    【讨论】:

    • 那么,我该如何分配半径呢?动画效果如何?
    猜你喜欢
    • 2017-12-12
    • 1970-01-01
    • 2012-01-03
    • 2011-09-14
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多