From 269157239278e7d9a4bdcf03d2eaa8956f07ce17 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Thu, 9 Sep 2021 13:09:26 +0530 Subject: [PATCH] Apply lastLineFillPercent for single line views as well. (#449) * Apply lastLineFillPercent for single line views as well. Fixes #430 * Update readme to include single_lastline.png * Remove singleline_lastline.png asset added to demo last line in single line views. * Simplify lastLineFillPercent related update in readme file. * Fix grammar in readme. --- README.md | 2 +- .../Sources/Internal/UIKitExtensions/CALayer+Extensions.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7abcf655..c734f7c4 100755 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ You can set some properties for multilines elements. | Property | Values | Default | Preview | ------- | ------- |------- | ------- -| **Filling percent** of the last line. | `0...100` | `70%` | ![](Assets/multiline_lastline.png) +| **Filling percent** of the last line.
Please note that for views without multiple lines, the single line will be considered as the last line and **lastLineFillPercent** will be applied to that single line. | `0...100` | `70%`| ![](Assets/multiline_lastline.png) | **Corner radius** of lines. (**NEW**) | `0...10` | `0` | ![](Assets/multiline_corner.png) diff --git a/SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift b/SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift index 9aa6f81f..aac5d350 100644 --- a/SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift +++ b/SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift @@ -108,7 +108,7 @@ private extension CALayer { func calculatedWidthForLine(at index: Int, totalLines: Int, lastLineFillPercent: Int, paddingInsets: UIEdgeInsets) -> CGFloat { var width = bounds.width - paddingInsets.left - paddingInsets.right - if index == totalLines - 1 && totalLines != 1 { + if index == totalLines - 1 { width = width * CGFloat(lastLineFillPercent) / 100 } return width @@ -197,7 +197,7 @@ extension CALayer { width: size.width, height: size.height) - if index == totalLines - 1 && totalLines != 1 { + if index == totalLines - 1 { frame = alignLayerFrame(newFrame, alignment: alignment, isRTL: isRTL) } else { frame = newFrame