์ด๋ ๊ฒ ๊ทธ๋ฆผ๊ณผ ๊ธ์๊ฐ ์์ง์ผ๋ก ๋ฐฐ์น๋๋ ๊ฒฝ์ฐ๊ฐ ์ข ์ข ์๋๋ฐ
์ด๋ ์๋ ์ฝ๋๋ฅผ ์ฌ์ฉํ๋ฉด ์ฝ๊ฒ ์์ง ๋ฐฐ์นํ ์ ์๋ค
์ถ์ฒ
https://velog.io/@ezidayzi/iOS-UIButton-title-image-align-%ED%95%98%EA%B8%B0
[iOS] UIButton title , image vertical align ํ๊ธฐ
UIButton๋ฅผ extesionํด์ ์์ ๋ฃ์ด๋๊ณ ์ฌ์ฉํ๋ฉด ํธ๋ฆฌํ๋ค.๐ณ
velog.io
extension UIButton {
func alignTextBelow(spacing: CGFloat = 8.0) {
guard let image = self.imageView?.image else {
return
}
guard let titleLabel = self.titleLabel else {
return
}
guard let titleText = titleLabel.text else {
return
}
let titleSize = titleText.size(withAttributes: [
NSAttributedString.Key.font: titleLabel.font as Any
])
titleEdgeInsets = UIEdgeInsets(top: spacing, left: -image.size.width, bottom: -image.size.height, right: 0)
imageEdgeInsets = UIEdgeInsets(top: -(titleSize.height + spacing), left: 0, bottom: 0, right: -titleSize.width)
}
}
๋ค๋ง ๋ฌธ์ ์ ์...
deprecate!!!
Hig์์๋ ํ์ธํ ์ ์๋ฏ์ด 15.0์์๋ UIButto.Configuration์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ๋ค
if #available(iOS 15.0, *) {
var configuration = UIButton.Configuration.plain()
configuration.title = "๊ด์ฌ ์ํ"
configuration.image = UIImage(named: "detail_bookmark_off")
configuration.imagePadding = 2
configuration.imagePlacement = .top
configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
button.configuration = configuration
}
configuration์ ์ฌ์ฉํ๋ฉด ์์ฃผ ์ฝ๊ฒ ์ด๋ฏธ์ง์ ํ์ดํ์ ์์ง์ผ๋ก ๋ฐฐ์นํ ์ ์๋ค
configuration.imagePlacement๋ฅผ ์ฌ์ฉํด์ ์ด๋ฏธ์ง์ ํ์ดํ ๋ฐฐ์น๋ฅผ ์ธํ ํด ์ค ์ ์๋ค.
์ด์ฐธ์ Configuration ๊ณต๋ถ์ข ํด๋ฌ์ผ ๊ฒ ๋น๐ฉ๐ป๐ป
'๐ iOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] MVVMC ์์ธํ ์์๋ณด๊ธฐ - ํํ ๋ฆฌ์ผ 1 (Coordinator์ AppCoordinator ๊ตฌํํ๊ธฐ) (0) | 2022.07.10 |
---|---|
[iOS/Swift] UIButton in iOS15 WWDC ์ ๋ฆฌ (0) | 2022.06.29 |
[iOS/Swift] UICollectionViewCell ์์๋ณด๊ธฐ (0) | 2022.06.27 |
[iOS] Notification Service Extension์ Firebase ์ ๋ฆฌ (0) | 2022.06.15 |
[Swift] MVVMC์ Coordinator ์์๋ณด๊ธฐ (0) | 2022.06.14 |
๋๊ธ