-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] 삭제버튼 text와 Image간 변환 기능 추가, Preview extension 생성
- Loading branch information
Showing
7 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
[1]Calculator.xcodeproj/xcuserdata/dj.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Bucket | ||
uuid = "BBBF4054-CF00-4C35-8797-88172D131DB6" | ||
type = "1" | ||
version = "2.0"> | ||
</Bucket> |
21 changes: 21 additions & 0 deletions
21
[1]Calculator/Assets.xcassets/deleteButton.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "free-icon-delete-2087825.png", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+7.4 KB
[1]Calculator/Assets.xcassets/deleteButton.imageset/free-icon-delete-2087825.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Extensions.swift | ||
// [1]Calculator | ||
// | ||
// Created by 김동준 on 12/5/24. | ||
// | ||
|
||
import UIKit | ||
import SwiftUI | ||
|
||
extension UIImage { | ||
func resize(size: CGSize) -> UIImage? { | ||
// 비트맵 생성 | ||
UIGraphicsBeginImageContextWithOptions(size, false, 0.0) | ||
// 비트맵 그래픽 배경에 이미지 다시 그리기 | ||
self.draw(in: CGRect(origin: CGPoint.zero, size: size)) | ||
// 현재 비트맵 그래픽 배경에서 이미지 가져오기 | ||
guard let resizedImage = UIGraphicsGetImageFromCurrentImageContext() else { | ||
return nil | ||
} | ||
// 비트맵 환경 제거 | ||
UIGraphicsEndImageContext() | ||
// 크기가 조정된 이미지 반환 | ||
return resizedImage | ||
} | ||
} | ||
|
||
// MARK: - SwiftUI Preview | ||
|
||
#if DEBUG | ||
import SwiftUI | ||
|
||
extension UIViewController { | ||
private struct Preview: UIViewControllerRepresentable { | ||
let viewController: UIViewController | ||
|
||
func makeUIViewController(context: Context) -> UIViewController { | ||
return viewController | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) { | ||
} | ||
} | ||
|
||
func toPreview() -> some View { | ||
Preview(viewController: self) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// ImageChangeManager.swift | ||
// [1]Calculator | ||
// | ||
// Created by 김동준 on 12/5/24. | ||
// | ||
|
||
import UIKit | ||
|
||
struct ImageChangeManager { | ||
func changeImage(_ button: UIButton, _ label: UILabel) { | ||
let originalImage = UIImage(named: "deleteButton") | ||
let changedImage = originalImage?.resize(size: CGSize(width: 50, height: 50))?.withTintColor(.white) | ||
|
||
if label.text != "0" { | ||
button.setTitle("", for: .normal) | ||
button.setImage(changedImage, for: .normal) | ||
} else { | ||
button.setTitle("AC", for: .normal) | ||
button.setImage(nil, for: .normal) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters