ios - 按钮中 UIImage 后的随机三个点

标签 ios swift uibutton uiimage

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

这是我正在使用的按钮:playButton

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

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
}()

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

Screenshot from the simulator

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

最佳答案

试试这个:

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
}()

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

关于ios - 按钮中 UIImage 后的随机三个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43840009/

相关文章:

ios - 在 UIButton 中创建三角形

php - Openssl RSA加密-解密

ios - 推送 segue 在 IOS 8.0 上不起作用

swift - 当按钮覆盖在 tableview 顶部时,如何防止 tableview 单元格注册点击?

ios - 适用于 iOS 的 Swift TableView

objective-c - UIControlStateHighlighted 的奇怪问题

ios - 设置条形图的顶部和底部间距 - iOS 图表

android - 在多个设备上同步通知

ios - 使用 Icon 创建标签实用程序

ios - 按钮外观点击版本