Skip to content

Commit

Permalink
Merge pull request #353 from lsj8706/fix/#352-콕찌르기-이미지뷰-조정
Browse files Browse the repository at this point in the history
[Fix] #352 콕찌르기 이미지 뷰 조정
  • Loading branch information
lsj8706 authored Jan 21, 2024
2 parents ff1e627 + 3ad654d commit a038731
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions SOPT-iOS/Projects/Core/Sources/Extension/Foundation+/String+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,30 @@ public extension String {
return map({String($0)}).last
}
}

public extension String {
func isPercentEncoded() -> Bool {
guard let decodedString = self.removingPercentEncoding,
let decodedData = decodedString.data(using: .utf8)
else { return false }

let encodedData = self.data(using: .utf8)

return encodedData != decodedData
}

func removePercentEncodingIfNeeded() -> String {
func removePercentEncodingRecursively(with string: String, attempts: Int) -> String {
guard attempts > 0 else { return string }

let decodedString = string.removingPercentEncoding ?? string
return decodedString.isPercentEncoded() ? removePercentEncodingRecursively(with: decodedString, attempts: attempts - 1) : decodedString
}

guard isPercentEncoded(),
let decodedString = self.removingPercentEncoding
else { return self }

return removePercentEncodingRecursively(with: decodedString, attempts: 2)
}
}
8 changes: 8 additions & 0 deletions SOPT-iOS/Projects/Core/Sources/Utils/setImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import Kingfisher

public extension UIImageView {
func setImage(with urlString: String, placeholder: UIImage? = nil, completion: ((UIImage?) -> Void)? = nil) {
guard let urlString = urlString
.removePercentEncodingIfNeeded()
.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
else {
print("URL 인코딩 실패")
return
}

let cache = ImageCache.default
if urlString == "" {
self.image = placeholder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public final class PokeProfileCardView: UIView, PokeCompatible {
imageView.backgroundColor = DSKitAsset.Colors.gray700.color
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFill
imageView.image = DSKitAsset.Assets.iconDefaultProfile.image
return imageView
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public final class PokeProfileImageView: UIImageView {

private func setUI() {
self.backgroundColor = DSKitAsset.Colors.gray700.color
self.image = DSKitAsset.Assets.iconDefaultProfile.image
self.clipsToBounds = true
self.layer.borderWidth = 2
self.contentMode = .scaleAspectFill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public final class ProfileCardGroupView: UIView, PokeCompatible {
// MARK: - UI Components

private let friendProfileImageView = UIImageView().then {
$0.image = DSKitAsset.Assets.iconDefaultProfile.image
$0.layer.cornerRadius = 15
$0.backgroundColor = DSKitAsset.Colors.gray700.color
$0.clipsToBounds = true
$0.contentMode = .scaleAspectFill
}

private let friendNameLabel = UILabel().then {
Expand Down

0 comments on commit a038731

Please sign in to comment.