UIToolbar 🍎

YaR LabΒ·2023λ…„ 8μ›” 14일
0

iOS 🍎

λͺ©λ‘ 보기
15/26
post-thumbnail

1️⃣ μ •μ˜

μΈν„°νŽ˜μ΄μŠ€μ˜ ν•˜λ‹¨ κ°€μž₯μžλ¦¬μ— ν•˜λ‚˜ μ΄μƒμ˜ λ²„νŠΌμ„ ν‘œμ‹œν•˜λŠ” 컨트둀

@MainActor
class UIToolbar : UIView

2️⃣ μ„€λͺ…

  • νˆ΄λ°” ν•­λͺ©μ„ μƒμ„±ν•˜λ €λ©΄ UIBarButtonItem 클래슀λ₯Ό μ‚¬μš©ν•¨
  • νˆ΄λ°”μ— νˆ΄λ°” ν•­λͺ©μ„ μΆ”κ°€ν•˜λ €λ©΄ setItems(_:animated:) λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•¨
  • μ•„μ΄ν…œμ˜ 일반 및 κ°•μ‘°λœ μƒνƒœλ₯Ό λ‚˜νƒ€λ‚΄λŠ” νˆ΄λ°” μ΄λ―Έμ§€λŠ” UIBarItem ν΄λž˜μŠ€λ‘œλΆ€ν„° 상속받은 image 속성을 μ‚¬μš©ν•˜μ—¬ μ„€μ •ν•œ μ΄λ―Έμ§€μ—μ„œ νŒŒμƒλ¨
  • νˆ΄λ°”μ˜ tintColorκ°€ μ΄λ―Έμ§€μ˜ 색상을 결정함
  • λΌλ””μ˜€ λ²„νŠΌ μŠ€νƒ€μΌ 컨트둀이 ν•„μš”ν•œ 경우 UIToolbar λŒ€μ‹  UITabBar 클래슀λ₯Ό μ‚¬μš©

πŸ“Œ Customize appearance

  • νˆ΄λ°”μ˜ 외관을 μ‚¬μš©μž μ •μ˜ν•˜λ €λ©΄ μ•„λž˜ λ‚˜μ—΄λœ λ©”μ„œλ“œλ₯Ό μ‚¬μš©
  • λͺ¨λ“  νˆ΄λ°”λ₯Ό μ‚¬μš©μž μ •μ˜ν•˜λ €λ©΄ μ™Έκ΄€ ν”„λ‘μ‹œ([UIToolbar appearance])에 setter λ©”μ‹œμ§€λ₯Ό λ³΄λ‚΄κ±°λ‚˜ νŠΉμ • UIToolbar μΈμŠ€ν„΄μŠ€μ— 보내야함

    μ™Έκ΄€ ν”„λ‘μ‹œ([UIToolbar appearance])

    • μ•± μ „μ²΄μ—μ„œ μΌκ΄„μ μœΌλ‘œ νŠΉμ • UI μš”μ†Œμ˜ 외관을 μ„€μ •ν•  수 μžˆλŠ” 방법
    • 이 ν”„λ‘μ‹œλ₯Ό μ‚¬μš©ν•˜λ©΄ μ•± μ „μ²΄μ—μ„œ μ‚¬μš©λ˜λŠ” νˆ΄λ°”μ˜ 외관을 ν•œ λ²ˆμ— μ„€μ •ν•  수 있음
    • iOS 13 μ΄ν›„μ—λŠ” standardAppearance 및 compactAppearance 속성을 μ‚¬μš©ν•˜μ—¬ νˆ΄λ°”λ₯Ό μ‚¬μš©μž μ •μ˜
    let toolbarAppearance = UIToolbar.appearance()
    toolbarAppearance.backgroundColor = UIColor.red
  • νŠΉμ • 속성이 λ°” λ©”νŠΈλ¦­μŠ€μ— 따라 λ‹¬λΌμ§ˆ λ•Œμ—λŠ” 일반적으둜 UIBarMetrics.default 및 landscapePhone에 λŒ€ν•΄ 값을 지정해야 함

    UIBarMetrics

    • UI μš”μ†Œμ˜ 크기와 μœ„μΉ˜λ₯Ό μ§€μ •ν•˜λŠ”λ° μ‚¬μš©λ˜λŠ” κ°’
    • λ°” λ©”νŠΈλ¦­μŠ€λŠ” νˆ΄λ°”λ‚˜ λ‚΄λΉ„κ²Œμ΄μ…˜ 바와 같은 λ°”(Bar)에 적용되며, ν•΄λ‹Ή λ°”μ˜ 크기 및 μœ„μΉ˜μ— 따라 λ‹€λ₯Έ μ™Έκ΄€ 섀정을 μ μš©ν•  수 μžˆλ„λ‘ 함
    // Using the appearance proxy to set different >background colors for different bar metrics
    let toolbarAppearance = UIToolbar.appearance()
    
    // Set background color for default (standard) >toolbar
    toolbarAppearance.backgroundColor = UIColor.blue
    
    // Set background color for compact toolbar (e.g., landscapePhone)
    toolbarAppearance.setBackgroundImage(UIImage(named: "compactBackgroundImage"), for: .compact)

    landscapePhone

    • UIBarMetrics의 ν•˜λ‚˜λ‘œ, 화면이 κ°€λ‘œ λ°©ν–₯으둜 μ „ν™˜λœ κ²½μš°μ— ν•΄λ‹Ήν•˜λŠ” λ°”μ˜ 크기와 μœ„μΉ˜λ₯Ό λ‚˜νƒ€λƒ„
    • λ””λ°”μ΄μŠ€κ°€ κ°€λ‘œ λͺ¨λ“œ(landscape mode)둜 μ „ν™˜λ˜μ—ˆμ„ λ•Œ μ μš©λ˜λŠ” λ°”μ˜ λ©”νŠΈλ¦­μŠ€
    // Using the appearance proxy to set different tint colors for different bar metrics
    let toolbarAppearance = UIToolbar.appearance()
    
    // Set tint color for default (standard) toolbar
    toolbarAppearance.tintColor = UIColor.red
    
    // Set tint color for compact toolbar in landscape mode
    toolbarAppearance.setTintColor(UIColor.green, for: .landscapePhone)
  • var standardAppearance: UIToolbarAppearance : ν‘œμ€€ 높이 νˆ΄λ°”μ— μ‚¬μš©ν•  μ™Έκ΄€ μ„€μ •
  • var compactAppearance: UIToolbarAppearance? : 콀팩트 높이 νˆ΄λ°”μ— μ‚¬μš©ν•  μ™Έκ΄€ μ„€μ •
  • var scrollEdgeAppearance: UIToolbarAppearance? : 슀크둀 κ°€λŠ₯ν•œ μ½˜ν…μΈ μ˜ κ°€μž₯μžλ¦¬κ°€ νˆ΄λ°”μ˜ κ°€μž₯μžλ¦¬μ™€ 정렬될 λ•Œ ν‘œμ€€ 높이 νˆ΄λ°”μ— λŒ€ν•œ μ™Έκ΄€ μ„€μ •
  • var compactScrollEdgeAppearance: UIToolbarAppearance? : 슀크둀 κ°€λŠ₯ν•œ μ½˜ν…μΈ μ˜ κ°€μž₯μžλ¦¬κ°€ 콀팩트 높이 νˆ΄λ°”μ˜ κ°€μž₯μžλ¦¬μ™€ 정렬될 λ•Œ 콀팩트 높이 νˆ΄λ°”μ— λŒ€ν•œ μ™Έκ΄€ μ„€μ •
  • var isTranslucent: Bool : νˆ΄λ°”κ°€ 반투λͺ…ν•œμ§€ μ—¬λΆ€λ₯Ό λ‚˜νƒ€λ‚΄λŠ” λΆ€μšΈ κ°’

μΆœμ²˜πŸ“š

🍎Apple Docs: UIToolbar

0개의 λŒ“κΈ€

κ΄€λ ¨ μ±„μš© 정보