Skip to content

Commit e76ee71

Browse files
committed
Determine corner radius automatically from the size of the slider's bounds if no corner radius is set
1 parent 1a61deb commit e76ee71

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

TactileSlider/Classes/TactileSlider.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,15 @@ import UIKit
9999
}
100100

101101
/// The radius of the rounded corners of the slider
102-
@IBInspectable open var cornerRadius: CGFloat = 16 {
102+
///
103+
/// Note: If this is set to a negative value (or left as default in interface builder), the corner radius will be automatically determined from the size of the bounds
104+
@IBInspectable open var cornerRadius: CGFloat = -1 {
103105
didSet {
104-
renderer.cornerRadius = cornerRadius
106+
if cornerRadius < 0 {
107+
renderer.cornerRadius = min(bounds.width, bounds.height) / 3.3
108+
} else {
109+
renderer.cornerRadius = cornerRadius
110+
}
105111
}
106112
}
107113

@@ -331,6 +337,9 @@ import UIKit
331337
}
332338

333339
private func updateLayerFrames() {
340+
if cornerRadius < 0 {
341+
renderer.cornerRadius = min(bounds.width, bounds.height) / 3.3
342+
}
334343
renderer.updateBounds(bounds)
335344
}
336345

0 commit comments

Comments
 (0)