【问题标题】:UIButton remove border with overlay on touchUIButton 删除边框与触摸覆盖
【发布时间】:2012-11-21 17:57:41
【问题描述】:

我需要一个 UIButton,但我不想要它的边框。

但是,当有人触摸按钮时,我仍然希望保持漂亮的渐变叠加

就像在 Facebook iPad 应用程序上一样,它们在动态消息中的文本链接在您触摸它们时会显示一个灰色框覆盖。

我在这里看到了一个关于使用 UISegmentedControl 的解决方案。但是我不想在解决方案中使用渐变/Quartz 框架。

以前有人遇到过这个问题吗?

更新

这是一个插图

(1) 是在您触摸之前 (2) 是当您触摸按钮时发生的情况。

我基本上只是想复制这种效果,我猜是透明的“覆盖”,就像你触摸按钮时发生的那样,但没有边框。

【问题讨论】:

  • 也许包括我们这些不使用 Facebook 的人的屏幕截图?
  • [link]tinypic.com/r/160tmo/6 (1) 在您触摸之前 (2) 是在您触摸链接时发生的情况。我基本上只是想复制这种效果,我猜是透明的“覆盖”,就像你触摸按钮时发生的那样,但没有边框
  • 请不要在与 Xcode 无关的问题上使用xcode 标签。

标签: objective-c ios cocoa-touch uibutton


【解决方案1】:

使用以下内容:

UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeCustom];
[yourButton setFrame:CGRectMake(0, 0, 200, 44)];
[yourButton setTitle:@"like" forState:UIControlStateNormal];

[yourButton setBackgroundImage:[UIImage imageNamed:@"normal.png"] forState:UIControlStateNormal];
[yourButton setBackgroundImage:[UIImage imageNamed:@"gradient.png"] forState:UIControlStateHighlighted];

// Round corners? Requires Quartzcore framework
[yourButton.layer setCornerRadius:8.0f];
[yourButton.layer setMasksToBounds:YES];
[yourButton.layer setBorderWidth:0.0f];

【讨论】:

    【解决方案2】:

    制作一个你想要的颜色的 UIImage,并调用setBackgroundImage:forState: 获得高亮状态(当用户点击按钮时,按钮高亮);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      • 2021-06-07
      • 2023-04-05
      • 1970-01-01
      相关资源
      最近更新 更多