ios - Storyboard上的按钮看起来很奇怪

标签 ios xcode image uibutton

我正在尝试修复一个看起来很酷的按钮,但出于某种原因,它在 Storyboard中看起来真的很奇怪。有人知道为什么吗?

enter image description here

这就是我用我的图片作为背景时的样子

enter image description here

这就是我将图片设置为图像时的样子。

这是我为按钮使用的图像:

enter image description here

所以我的问题基本上是,是否可以使用此图像填充整个按钮区域以使其看起来不错?

谢谢

编辑

当我使用 andres 代码时:

enter image description here

编辑1

最终结果如下:

enter image description here

最佳答案

我想你必须在这样的代码中进行设置:

let insets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
let image = UIImage(named: "bt_bg")?.resizableImageWithCapInsets(insets)
button.setBackgroundImage(image, forState: .Normal)

插图指定要保留图像的哪些部分(在本例中为保留图像左侧和右侧圆角的 10 个点)以及要重复的部分(左侧和右侧 10 个点以内的所有内容) .

希望有帮助。

关于ios - Storyboard上的按钮看起来很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38054696/

相关文章:

ios - 我应该如何正确管理JSON提供的图像

ios - 依次运行两个 UIAlertController

ios - 使用 navigationController?.pushViewController (Swift 3.0) 获取黑屏

iPhone - 带有可点击 UITextView 的自定义 UITableViewCell

python - 如何存储和加载庞大的图像数据集?

ios - 设置 iOS 导航背景颜色无法正常工作

ios - 使用 Kii 查询结果

xcode - 在需要时配置 Xcode 4 工作区以构建依赖项的正确方法是什么?

c++ - FLTK-不显示Mac iOS图像

image - 使用golang获取图片大小