46 lines
1.2 KiB
Swift
46 lines
1.2 KiB
Swift
|
//
|
||
|
// UIButton.swift
|
||
|
// Mastodon
|
||
|
//
|
||
|
// Created by sxiaojian on 2021/2/1.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
extension UIButton {
|
||
|
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
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|