UISlider: changed hight, but maximum value flashes
I customised a UISlider
and everything works well except when I drag the slider to 100%. Then the rounded caps are replaced with a square.
Here is how I customize the Slider:
@IBInspectable var trackHeight: CGFloat = 14
override func trackRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(origin: bounds.origin, size: CGSize(width: bounds.width, height: trackHeight))
}
98% image:
100% image:
ios swift uiview uislider
add a comment |
I customised a UISlider
and everything works well except when I drag the slider to 100%. Then the rounded caps are replaced with a square.
Here is how I customize the Slider:
@IBInspectable var trackHeight: CGFloat = 14
override func trackRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(origin: bounds.origin, size: CGSize(width: bounds.width, height: trackHeight))
}
98% image:
100% image:
ios swift uiview uislider
add a comment |
I customised a UISlider
and everything works well except when I drag the slider to 100%. Then the rounded caps are replaced with a square.
Here is how I customize the Slider:
@IBInspectable var trackHeight: CGFloat = 14
override func trackRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(origin: bounds.origin, size: CGSize(width: bounds.width, height: trackHeight))
}
98% image:
100% image:
ios swift uiview uislider
I customised a UISlider
and everything works well except when I drag the slider to 100%. Then the rounded caps are replaced with a square.
Here is how I customize the Slider:
@IBInspectable var trackHeight: CGFloat = 14
override func trackRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(origin: bounds.origin, size: CGSize(width: bounds.width, height: trackHeight))
}
98% image:
100% image:
ios swift uiview uislider
ios swift uiview uislider
edited Nov 12 '18 at 13:21
Kuldeep
2,47441534
2,47441534
asked Nov 12 '18 at 13:16
netshark1000
3,49743869
3,49743869
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Here some quick solution
You have changed frame of the line, the height is higher the default and that's why you see it.
You can move little bit slider at the 100%.
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
var rect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
if value > 0.99 {
rect = CGRect(x: rect.origin.x+2, y: rect.origin.y, width: rect.size.width, height: rect.size.height)
}
return rect
}
Or you can make the thumb bigger to cover the corners, its up to you.
but why is it ok while (>1 value <100) ?
– netshark1000
Nov 12 '18 at 13:49
nope, value here is started from 0.0 to 1.0 )
– Gkolunia
Nov 12 '18 at 13:51
I replaced your 0.99 with 99
– netshark1000
Nov 12 '18 at 13:52
sorry i've used default settings for minimum and maximum value. And its 0.0 to 1.0.
– Gkolunia
Nov 12 '18 at 13:53
let normalizedValue = value / maximumValue if normalizedValue > 0.98 { solves this
– netshark1000
Nov 12 '18 at 14:04
add a comment |
Original answer here: Thumb image does not move to the edge of UISlider
updated to swift 4.2:
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
let unadjustedThumbrect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
let thumbOffsetToApplyOnEachSide:CGFloat = unadjustedThumbrect.size.width / 2.0
let minOffsetToAdd = -thumbOffsetToApplyOnEachSide
let maxOffsetToAdd = thumbOffsetToApplyOnEachSide
let offsetForValue = minOffsetToAdd + (maxOffsetToAdd - minOffsetToAdd) * CGFloat(value / (self.maximumValue - self.minimumValue))
var origin = unadjustedThumbrect.origin
origin.x += offsetForValue
return CGRect(origin: origin, size: unadjustedThumbrect.size)
}
the edges are still there. Nothing changed
– netshark1000
Nov 12 '18 at 13:42
Strange, works fine for me, have you implemented this code inside yourUISlider
subclass?
– Arie Pinto
Nov 12 '18 at 13:49
Yes, also I implemented track rect. Value Max is 100 not 1
– netshark1000
Nov 12 '18 at 13:51
Ok, i changed to 100 and still working, whattrackHeight
are you testing it with?
– Arie Pinto
Nov 12 '18 at 13:55
with 14. Do I see it right that I have to mimimize the frame of my slider so that there is space for the thumb which needs more space now?
– netshark1000
Nov 12 '18 at 13:56
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262990%2fuislider-changed-hight-but-maximum-value-flashes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here some quick solution
You have changed frame of the line, the height is higher the default and that's why you see it.
You can move little bit slider at the 100%.
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
var rect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
if value > 0.99 {
rect = CGRect(x: rect.origin.x+2, y: rect.origin.y, width: rect.size.width, height: rect.size.height)
}
return rect
}
Or you can make the thumb bigger to cover the corners, its up to you.
but why is it ok while (>1 value <100) ?
– netshark1000
Nov 12 '18 at 13:49
nope, value here is started from 0.0 to 1.0 )
– Gkolunia
Nov 12 '18 at 13:51
I replaced your 0.99 with 99
– netshark1000
Nov 12 '18 at 13:52
sorry i've used default settings for minimum and maximum value. And its 0.0 to 1.0.
– Gkolunia
Nov 12 '18 at 13:53
let normalizedValue = value / maximumValue if normalizedValue > 0.98 { solves this
– netshark1000
Nov 12 '18 at 14:04
add a comment |
Here some quick solution
You have changed frame of the line, the height is higher the default and that's why you see it.
You can move little bit slider at the 100%.
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
var rect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
if value > 0.99 {
rect = CGRect(x: rect.origin.x+2, y: rect.origin.y, width: rect.size.width, height: rect.size.height)
}
return rect
}
Or you can make the thumb bigger to cover the corners, its up to you.
but why is it ok while (>1 value <100) ?
– netshark1000
Nov 12 '18 at 13:49
nope, value here is started from 0.0 to 1.0 )
– Gkolunia
Nov 12 '18 at 13:51
I replaced your 0.99 with 99
– netshark1000
Nov 12 '18 at 13:52
sorry i've used default settings for minimum and maximum value. And its 0.0 to 1.0.
– Gkolunia
Nov 12 '18 at 13:53
let normalizedValue = value / maximumValue if normalizedValue > 0.98 { solves this
– netshark1000
Nov 12 '18 at 14:04
add a comment |
Here some quick solution
You have changed frame of the line, the height is higher the default and that's why you see it.
You can move little bit slider at the 100%.
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
var rect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
if value > 0.99 {
rect = CGRect(x: rect.origin.x+2, y: rect.origin.y, width: rect.size.width, height: rect.size.height)
}
return rect
}
Or you can make the thumb bigger to cover the corners, its up to you.
Here some quick solution
You have changed frame of the line, the height is higher the default and that's why you see it.
You can move little bit slider at the 100%.
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
var rect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
if value > 0.99 {
rect = CGRect(x: rect.origin.x+2, y: rect.origin.y, width: rect.size.width, height: rect.size.height)
}
return rect
}
Or you can make the thumb bigger to cover the corners, its up to you.
answered Nov 12 '18 at 13:34
Gkolunia
828
828
but why is it ok while (>1 value <100) ?
– netshark1000
Nov 12 '18 at 13:49
nope, value here is started from 0.0 to 1.0 )
– Gkolunia
Nov 12 '18 at 13:51
I replaced your 0.99 with 99
– netshark1000
Nov 12 '18 at 13:52
sorry i've used default settings for minimum and maximum value. And its 0.0 to 1.0.
– Gkolunia
Nov 12 '18 at 13:53
let normalizedValue = value / maximumValue if normalizedValue > 0.98 { solves this
– netshark1000
Nov 12 '18 at 14:04
add a comment |
but why is it ok while (>1 value <100) ?
– netshark1000
Nov 12 '18 at 13:49
nope, value here is started from 0.0 to 1.0 )
– Gkolunia
Nov 12 '18 at 13:51
I replaced your 0.99 with 99
– netshark1000
Nov 12 '18 at 13:52
sorry i've used default settings for minimum and maximum value. And its 0.0 to 1.0.
– Gkolunia
Nov 12 '18 at 13:53
let normalizedValue = value / maximumValue if normalizedValue > 0.98 { solves this
– netshark1000
Nov 12 '18 at 14:04
but why is it ok while (>1 value <100) ?
– netshark1000
Nov 12 '18 at 13:49
but why is it ok while (>1 value <100) ?
– netshark1000
Nov 12 '18 at 13:49
nope, value here is started from 0.0 to 1.0 )
– Gkolunia
Nov 12 '18 at 13:51
nope, value here is started from 0.0 to 1.0 )
– Gkolunia
Nov 12 '18 at 13:51
I replaced your 0.99 with 99
– netshark1000
Nov 12 '18 at 13:52
I replaced your 0.99 with 99
– netshark1000
Nov 12 '18 at 13:52
sorry i've used default settings for minimum and maximum value. And its 0.0 to 1.0.
– Gkolunia
Nov 12 '18 at 13:53
sorry i've used default settings for minimum and maximum value. And its 0.0 to 1.0.
– Gkolunia
Nov 12 '18 at 13:53
let normalizedValue = value / maximumValue if normalizedValue > 0.98 { solves this
– netshark1000
Nov 12 '18 at 14:04
let normalizedValue = value / maximumValue if normalizedValue > 0.98 { solves this
– netshark1000
Nov 12 '18 at 14:04
add a comment |
Original answer here: Thumb image does not move to the edge of UISlider
updated to swift 4.2:
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
let unadjustedThumbrect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
let thumbOffsetToApplyOnEachSide:CGFloat = unadjustedThumbrect.size.width / 2.0
let minOffsetToAdd = -thumbOffsetToApplyOnEachSide
let maxOffsetToAdd = thumbOffsetToApplyOnEachSide
let offsetForValue = minOffsetToAdd + (maxOffsetToAdd - minOffsetToAdd) * CGFloat(value / (self.maximumValue - self.minimumValue))
var origin = unadjustedThumbrect.origin
origin.x += offsetForValue
return CGRect(origin: origin, size: unadjustedThumbrect.size)
}
the edges are still there. Nothing changed
– netshark1000
Nov 12 '18 at 13:42
Strange, works fine for me, have you implemented this code inside yourUISlider
subclass?
– Arie Pinto
Nov 12 '18 at 13:49
Yes, also I implemented track rect. Value Max is 100 not 1
– netshark1000
Nov 12 '18 at 13:51
Ok, i changed to 100 and still working, whattrackHeight
are you testing it with?
– Arie Pinto
Nov 12 '18 at 13:55
with 14. Do I see it right that I have to mimimize the frame of my slider so that there is space for the thumb which needs more space now?
– netshark1000
Nov 12 '18 at 13:56
|
show 1 more comment
Original answer here: Thumb image does not move to the edge of UISlider
updated to swift 4.2:
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
let unadjustedThumbrect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
let thumbOffsetToApplyOnEachSide:CGFloat = unadjustedThumbrect.size.width / 2.0
let minOffsetToAdd = -thumbOffsetToApplyOnEachSide
let maxOffsetToAdd = thumbOffsetToApplyOnEachSide
let offsetForValue = minOffsetToAdd + (maxOffsetToAdd - minOffsetToAdd) * CGFloat(value / (self.maximumValue - self.minimumValue))
var origin = unadjustedThumbrect.origin
origin.x += offsetForValue
return CGRect(origin: origin, size: unadjustedThumbrect.size)
}
the edges are still there. Nothing changed
– netshark1000
Nov 12 '18 at 13:42
Strange, works fine for me, have you implemented this code inside yourUISlider
subclass?
– Arie Pinto
Nov 12 '18 at 13:49
Yes, also I implemented track rect. Value Max is 100 not 1
– netshark1000
Nov 12 '18 at 13:51
Ok, i changed to 100 and still working, whattrackHeight
are you testing it with?
– Arie Pinto
Nov 12 '18 at 13:55
with 14. Do I see it right that I have to mimimize the frame of my slider so that there is space for the thumb which needs more space now?
– netshark1000
Nov 12 '18 at 13:56
|
show 1 more comment
Original answer here: Thumb image does not move to the edge of UISlider
updated to swift 4.2:
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
let unadjustedThumbrect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
let thumbOffsetToApplyOnEachSide:CGFloat = unadjustedThumbrect.size.width / 2.0
let minOffsetToAdd = -thumbOffsetToApplyOnEachSide
let maxOffsetToAdd = thumbOffsetToApplyOnEachSide
let offsetForValue = minOffsetToAdd + (maxOffsetToAdd - minOffsetToAdd) * CGFloat(value / (self.maximumValue - self.minimumValue))
var origin = unadjustedThumbrect.origin
origin.x += offsetForValue
return CGRect(origin: origin, size: unadjustedThumbrect.size)
}
Original answer here: Thumb image does not move to the edge of UISlider
updated to swift 4.2:
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
let unadjustedThumbrect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
let thumbOffsetToApplyOnEachSide:CGFloat = unadjustedThumbrect.size.width / 2.0
let minOffsetToAdd = -thumbOffsetToApplyOnEachSide
let maxOffsetToAdd = thumbOffsetToApplyOnEachSide
let offsetForValue = minOffsetToAdd + (maxOffsetToAdd - minOffsetToAdd) * CGFloat(value / (self.maximumValue - self.minimumValue))
var origin = unadjustedThumbrect.origin
origin.x += offsetForValue
return CGRect(origin: origin, size: unadjustedThumbrect.size)
}
answered Nov 12 '18 at 13:39
Arie Pinto
763615
763615
the edges are still there. Nothing changed
– netshark1000
Nov 12 '18 at 13:42
Strange, works fine for me, have you implemented this code inside yourUISlider
subclass?
– Arie Pinto
Nov 12 '18 at 13:49
Yes, also I implemented track rect. Value Max is 100 not 1
– netshark1000
Nov 12 '18 at 13:51
Ok, i changed to 100 and still working, whattrackHeight
are you testing it with?
– Arie Pinto
Nov 12 '18 at 13:55
with 14. Do I see it right that I have to mimimize the frame of my slider so that there is space for the thumb which needs more space now?
– netshark1000
Nov 12 '18 at 13:56
|
show 1 more comment
the edges are still there. Nothing changed
– netshark1000
Nov 12 '18 at 13:42
Strange, works fine for me, have you implemented this code inside yourUISlider
subclass?
– Arie Pinto
Nov 12 '18 at 13:49
Yes, also I implemented track rect. Value Max is 100 not 1
– netshark1000
Nov 12 '18 at 13:51
Ok, i changed to 100 and still working, whattrackHeight
are you testing it with?
– Arie Pinto
Nov 12 '18 at 13:55
with 14. Do I see it right that I have to mimimize the frame of my slider so that there is space for the thumb which needs more space now?
– netshark1000
Nov 12 '18 at 13:56
the edges are still there. Nothing changed
– netshark1000
Nov 12 '18 at 13:42
the edges are still there. Nothing changed
– netshark1000
Nov 12 '18 at 13:42
Strange, works fine for me, have you implemented this code inside your
UISlider
subclass?– Arie Pinto
Nov 12 '18 at 13:49
Strange, works fine for me, have you implemented this code inside your
UISlider
subclass?– Arie Pinto
Nov 12 '18 at 13:49
Yes, also I implemented track rect. Value Max is 100 not 1
– netshark1000
Nov 12 '18 at 13:51
Yes, also I implemented track rect. Value Max is 100 not 1
– netshark1000
Nov 12 '18 at 13:51
Ok, i changed to 100 and still working, what
trackHeight
are you testing it with?– Arie Pinto
Nov 12 '18 at 13:55
Ok, i changed to 100 and still working, what
trackHeight
are you testing it with?– Arie Pinto
Nov 12 '18 at 13:55
with 14. Do I see it right that I have to mimimize the frame of my slider so that there is space for the thumb which needs more space now?
– netshark1000
Nov 12 '18 at 13:56
with 14. Do I see it right that I have to mimimize the frame of my slider so that there is space for the thumb which needs more space now?
– netshark1000
Nov 12 '18 at 13:56
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262990%2fuislider-changed-hight-but-maximum-value-flashes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown