Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- 애니메이션
- uiscrollview
- ribs
- RxCocoa
- combine
- Human interface guide
- HIG
- Refactoring
- 클린 코드
- uitableview
- tableView
- 리팩토링
- collectionview
- Xcode
- UICollectionView
- Observable
- rxswift
- 리펙토링
- SWIFT
- map
- Protocol
- swift documentation
- clean architecture
- swiftUI
- ios
- 스위프트
- 리펙터링
- Clean Code
- MVVM
- UITextView
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] Floating Button (Hover 프레임워크) 본문
* floating 의미: "떠다니는"
floating button: 떠있는 듯한 버튼
음영효과로 FloatingStyle 주는 방법
- UIView에 extension으로 아래 함수 추가
extension UIView {
func setFloatingStyle() {
setShadow(color: .black, alpha: 0.2, xPoint: 0, yPoint: 6, blur: 10, spread: 0)
}
func setShadow(color: UIColor = .black,
alpha: Float,
xPoint: CGFloat,
yPoint: CGFloat,
blur: CGFloat,
spread: CGFloat) {
layer.shadowColor = color.cgColor
layer.shadowOpacity = alpha
layer.shadowOffset = CGSize(width: xPoint, height: yPoint)
layer.shadowRadius = blur / 2.0
if spread == 0 {
layer.shadowPath = nil
} else {
let diffx = -spread
let rect = layer.bounds.insetBy(dx: diffx, dy: diffx)
layer.shadowPath = UIBezierPath(rect: rect).cgPath
}
}
}
- 사용
button.setFloatingStyle()
Hover프레임워크
- 의존성
pod 'Hover'
- Hover 생성
private func setupBtnFloating() {
let hoverConfiguration = HoverConfiguration(
image: UIImage(systemName: "plus"),
color: .gradient(
top: UIColor.lightGray,
bottom: UIColor.lightGray
),
size: 45,
spacing: 16
)
let items = [
HoverItem(title: "photo", image: UIImage(systemName: "photo")!) { [weak self] in
print("photo tap event")
},
HoverItem(title: "switch", image: UIImage(systemName: "switch.2")!) { [weak self] in
print("switch tap event")
},
HoverItem(title: "flash", image: UIImage(systemName: "bolt.fill")!) { [weak self] in
print("flash tap event")
}
]
let hoverView = HoverView(with: hoverConfiguration, items: items)
hoverView.setFloatingStyle()
view.addSubview(hoverView)
hoverView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate(
[
hoverView.topAnchor.constraint(equalTo: view.topAnchor),
hoverView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
hoverView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
hoverView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
]
)
}
- 사용
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setupBtnFloating()
}
'iOS 응용 (swift)' 카테고리의 다른 글
[iOS - swift] popToRootViewController의 completion 인자를 가진 커스텀 함수 만드는 방법 (CATransaction 사용) (0) | 2021.01.12 |
---|---|
[iOS - swift] Localization, Localizable, 지역화 테스트 방법 (Programmtically, Storyboard, xib) (1) | 2021.01.11 |
[iOS - swift] 포커스 애니메이션 (0) | 2021.01.10 |
[iOS - swift] UIImage파일 관리 방법 (0) | 2021.01.10 |
[iOS - swift] UIView.animate() (0) | 2021.01.09 |
Comments