我收到警告:
'imageEdgeInsets' was deprecated in iOS 15.0
Run Code Online (Sandbox Code Playgroud)
当像这样设置 UIButton imageEdgeInsets 时:
button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
Run Code Online (Sandbox Code Playgroud)
我尝试像这样设置 imageEdgeInsets:
UIImage(named: "filter")?.withRenderingMode(.alwaysTemplate).withAlignmentRectInsets(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
Run Code Online (Sandbox Code Playgroud)
上、左、右、下都是正值或负值,没有运气。有谁知道版本的
imageEdgeInsets
Run Code Online (Sandbox Code Playgroud)
iOS 15 中没有弃用这一点吗?感谢所有帮助,亲切的问候:)
Raj*_*han 81
iOS 15 Apple 引入了 3 个新选项来控制填充和插入。
\n.titlePadding:标题和副标题标签之间的填充。.imagePadding:按钮\xe2\x80\x99s图像和文本之间的填充。.contentInsets:从按钮\xe2\x80\x99s 内容区域到其边界的填充。使用上述选项,您可以根据需要管理和设置按钮样式。
\n\n\n所以你的代码应该是这样的
\nvar configuration = UIButton.Configuration.filled()\nconfiguration.title = "Title"\nconfiguration.image = UIImage(systemName: "swift")\nconfiguration.titlePadding = 10\nconfiguration.imagePadding = 10\nconfiguration.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)\nRun Code Online (Sandbox Code Playgroud)\n
Vis*_*kse 11
Swift 现在默认带有不同类型的按钮,您可以从 iOS 15 开始进行设置。用于UIButton.Configuration设置您的按钮。对于您的情况,您可以使用,
config.imagePadding = 5
Run Code Online (Sandbox Code Playgroud)
下面是一个例子:
var filled = UIButton.Configuration.filled()
filled.title = "Filled button"
filled.buttonSize = .large
filled.subtitle = "With subtitle even"
filled.image = UIImage(systemName: "bubble.left.fill")
filled.imagePlacement = .trailing
filled.imagePadding = 5
let button = UIButton(configuration: filled, primaryAction: nil)
Run Code Online (Sandbox Code Playgroud)
图片和代码来源于nemecek.be