Skip to content

Commit 50f5740

Browse files
committed
Fixed issue with pagecontrol offset
1 parent d693a43 commit 50f5740

4 files changed

Lines changed: 32 additions & 17 deletions

File tree

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ For Swift Package Manager add the following package to your Package.swift:
2626

2727
Carthage is also supported, add FormView by adding to Cartfile:
2828
```
29-
github "fredyshox/PageView" ~> 1.3.1
29+
github "fredyshox/PageView" ~> 1.3.2
3030
```
3131

3232
## Demo
@@ -60,14 +60,15 @@ VPageView {
6060
By default PageView fills all the available area, you can constrain it's size using `.frame(width:, height:)` View modifier.
6161

6262
You can customize the styling of page control component by passing `PageControlTheme`. Customizable properties:
63-
* background color
64-
* active page dot color
65-
* inactive page dot color
66-
* size of page dot
67-
* spacing between dots
68-
* padding of page control
69-
* page control offset
70-
* alignment of page control component (default: bottom-center for horizontal axis, center-leading for vertical axis)
63+
* `backgroundColor`
64+
* `dotActiveColor`: active page dot color
65+
* `dotInactiveColor`: inactive page dot color
66+
* `dotSize`: size of page dot
67+
* `spacing`: spacing between dots
68+
* `padding`: padding of page control
69+
* `xOffset`: page control x-axis offset, used only in vertical mode
70+
* `yOffset`: page control y-axis offset, used only in horizontal mode
71+
* `alignment`: alignment of page control component (default: bottom-center in horizontal mode, center-leading in vertical mode)
7172

7273
```swift
7374
let theme = PageControlTheme(
@@ -77,7 +78,8 @@ let theme = PageControlTheme(
7778
dotSize: 10.0,
7879
spacing: 12.0,
7980
padding: 5.0,
80-
offset: 8.0,
81+
xOffset: 8.0,
82+
yOffset: -8.0,
8183
alignment: Alignment(horizontal: .trailing, vertical: .top)
8284
)
8385
...

Sources/PageControl.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public enum PageControl {
3535
public var body: some View {
3636
HStack(spacing: theme.spacing) {
3737
bodyCreator(pageCount, $selectedPage, theme)
38-
}.modifier(Background(theme: theme))
38+
}
39+
.modifier(Background(theme: theme))
40+
.offset(x: 0.0, y: theme.yOffset)
3941
}
4042
}
4143

@@ -50,7 +52,9 @@ public enum PageControl {
5052
public var body: some View {
5153
VStack(spacing: theme.spacing) {
5254
bodyCreator(pageCount, $selectedPage, theme)
53-
}.modifier(Background(theme: theme))
55+
}
56+
.modifier(Background(theme: theme))
57+
.offset(x: theme.xOffset, y: 0.0)
5458
}
5559
}
5660

Sources/PageControlTheme.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public struct PageControlTheme {
1414
public var dotSize: CGFloat
1515
public var spacing: CGFloat
1616
public var padding: CGFloat
17-
public var offset: CGFloat
17+
public var xOffset: CGFloat
18+
public var yOffset: CGFloat
1819
public var alignment: Alignment?
1920

2021
public static var `default`: PageControlTheme {
@@ -26,7 +27,8 @@ public struct PageControlTheme {
2627
dotSize: 7.0,
2728
spacing: 9.0,
2829
padding: 4.0,
29-
offset: 12.0,
30+
xOffset: 12.0,
31+
yOffset: -12.0,
3032
alignment: nil
3133
)
3234
#elseif os(watchOS)
@@ -37,7 +39,8 @@ public struct PageControlTheme {
3739
dotSize: 6.0,
3840
spacing: 5.0,
3941
padding: 2.0,
40-
offset: 0.0,
42+
xOffset: 0.0,
43+
yOffset: 0.0,
4144
alignment: nil
4245
)
4346
#else
@@ -48,7 +51,8 @@ public struct PageControlTheme {
4851
dotSize: 12.0,
4952
spacing: 8.0,
5053
padding: 8.0,
51-
offset: 16.0,
54+
xOffset: 16.0,
55+
yOffset: -16.0,
5256
alignment: nil
5357
)
5458
#endif

Sources/PageView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ struct PageView_Previews: PreviewProvider {
128128
.fontWeight(.bold)
129129
.foregroundColor(.gray)
130130
}
131-
return HPageView {
131+
132+
var theme = PageControlTheme.default
133+
theme.alignment = Alignment(horizontal: .center, vertical: .bottom)
134+
theme.yOffset = -14
135+
136+
return HPageView(theme: theme) {
132137
v1
133138
v2
134139
}

0 commit comments

Comments
 (0)