1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-15 10:24:32 +01:00
mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonExtension/UIButton.swift

54 lines
1.5 KiB
Swift

//
// UIButton.swift
//
//
// Created by MainasuK on 2022-1-17.
//
import UIKit
extension UIButton {
public func setInsets(
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
)
}
}
}
extension UIButton {
public func setBackgroundColor(_ color: UIColor, for state: UIControl.State) {
self.setBackgroundImage(
UIImage.placeholder(color: color),
for: state
)
}
}