【问题标题】:Random three dots following UIImage in button按钮中的 UIImage 后随机三个点
【发布时间】:2017-05-08 04:54:52
【问题描述】:

我正在尝试在聊天单元格 (UICollectionView Cell) 上叠加播放图像

这是我正在使用的按钮:

但是,我注意到我使用的每张图片都有这种效果。下面是我正在构建的按钮的代码。

let playButton: UIButton = {
    let button = UIButton(type: .system)
    button.setTitle("Play Video", for: .normal)
    button.translatesAutoresizingMaskIntoConstraints = false
    button.isUserInteractionEnabled = true
    let image = UIImage(named: "play")
    button.tintColor = UIColor.white
    button.setImage(image, for: .normal)
    return button
}()

这是它在模拟器中的样子:

为什么我的 UIImage 会附加这些点?

【问题讨论】:

  • 移除 UIButton 的 setTitle,因为您不需要为 Play Image 显示文本。
  • 它是按钮的标题,从playButton @Ricky Avina 中删除这行代码button.setTitle("Play Video", for: .normal)

标签: ios swift uibutton uiimage


【解决方案1】:

试试这个:

let playButton: UIButton = {
    let button = UIButton(type: .system)
    button.translatesAutoresizingMaskIntoConstraints = false
    button.isUserInteractionEnabled = true
    let image = UIImage(named: "play")
    button.tintColor = UIColor.white
    button.setImage(image, for: .normal)
    return button
}()

当您设置标题时,标题文本不适合按钮框架,因此您会看到三条虚线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多