2021-02-01 11:06:29 +01:00
|
|
|
//
|
|
|
|
// UIButton.swift
|
2022-01-27 14:23:39 +01:00
|
|
|
//
|
2021-02-01 11:06:29 +01:00
|
|
|
//
|
2022-01-27 14:23:39 +01:00
|
|
|
// Created by MainasuK on 2022-1-17.
|
2021-02-01 11:06:29 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
extension UIButton {
|
2022-01-27 14:23:39 +01:00
|
|
|
public func setInsets(
|
2021-02-01 11:06:29 +01:00
|
|
|
forContentPadding contentPadding: UIEdgeInsets,
|
|
|
|
imageTitlePadding: CGFloat
|
|
|
|
) {
|
|
|
|
switch UIApplication.shared.userInterfaceLayoutDirection {
|
|
|
|
case .rightToLeft:
|
|
|
|
self.contentEdgeInsets = UIEdgeInsets(
|
|
|
|
top: contentPadding.top,
|
|
|
|
left: contentPadding.left + imageTitlePadding,
|
|
|
|
bottom: contentPadding.bottom,
|
|
|
|
right: contentPadding.right
|
|
|
|
)
|
|
|
|
self.titleEdgeInsets = UIEdgeInsets(
|
|
|
|
top: 0,
|
|
|
|
left: -imageTitlePadding,
|
|
|
|
bottom: 0,
|
|
|
|
right: imageTitlePadding
|
|
|
|
)
|
|
|
|
default:
|
|
|
|
self.contentEdgeInsets = UIEdgeInsets(
|
|
|
|
top: contentPadding.top,
|
|
|
|
left: contentPadding.left,
|
|
|
|
bottom: contentPadding.bottom,
|
|
|
|
right: contentPadding.right + imageTitlePadding
|
|
|
|
)
|
|
|
|
self.titleEdgeInsets = UIEdgeInsets(
|
|
|
|
top: 0,
|
|
|
|
left: imageTitlePadding,
|
|
|
|
bottom: 0,
|
|
|
|
right: -imageTitlePadding
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-08 13:47:31 +02:00
|
|
|
extension UIButton {
|
2022-01-27 14:23:39 +01:00
|
|
|
public func setBackgroundColor(_ color: UIColor, for state: UIControl.State) {
|
2021-04-17 08:01:57 +02:00
|
|
|
self.setBackgroundImage(
|
|
|
|
UIImage.placeholder(color: color),
|
|
|
|
for: state
|
|
|
|
)
|
2021-04-08 13:47:31 +02:00
|
|
|
}
|
|
|
|
}
|