Skip to content

Commit 1768eff

Browse files
committed
Fixed layout for avatar view.
1 parent b9f9c29 commit 1768eff

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

NativeUIKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'NativeUIKit'
4-
s.version = '1.3.8'
4+
s.version = '1.3.9'
55
s.summary = 'Mimicrated views and controls to native Apple appearance.'
66
s.homepage = 'https://github.com/ivanvorobei/NativeUIKit'
77
s.source = { :git => 'https://github.com/ivanvorobei/NativeUIKit.git', :tag => s.version }

Sources/NativeUIKit/Views/NativeAvatarView.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ open class NativeAvatarView: SPView {
8989
}
9090
}
9191

92-
open var placeholderImage = UIImage.system("person.crop.circle.fill", font: .systemFont(ofSize: 80, weight: .medium)) {
92+
open var placeholderImage = generatePlaceholderImage(fontSize: 80, fontWeight: .medium) {
9393
didSet {
9494
placeholderButton.setImage(placeholderImage)
9595
}
@@ -164,10 +164,23 @@ open class NativeAvatarView: SPView {
164164
placeholderButton.sizeToFit()
165165
frame.setWidth(placeholderButton.frame.width + layoutMargins.left + layoutMargins.right)
166166
layoutSubviews()
167-
return .init(
168-
width: max(placeholderButton.frame.maxX, indicatorButton.frame.maxX) + layoutMargins.bottom,
169-
height: max(placeholderButton.frame.maxY, indicatorButton.frame.maxY) + layoutMargins.bottom
170-
)
167+
if isEditable {
168+
return .init(
169+
width: max(placeholderButton.frame.maxX, indicatorButton.frame.maxX) + layoutMargins.bottom,
170+
height: max(placeholderButton.frame.maxY, indicatorButton.frame.maxY) + layoutMargins.bottom
171+
)
172+
} else {
173+
return .init(
174+
width: placeholderButton.frame.maxX + layoutMargins.bottom,
175+
height: placeholderButton.frame.maxY + layoutMargins.bottom
176+
)
177+
}
178+
}
179+
180+
// MARK: - Public
181+
182+
static public func generatePlaceholderImage(fontSize: CGFloat, fontWeight: UIFont.Weight) -> UIImage {
183+
return UIImage.system("person.crop.circle.fill", font: .systemFont(ofSize: fontSize, weight: fontWeight))
171184
}
172185

173186
// MARK: - Internal

0 commit comments

Comments
 (0)