UISlider: changed hight, but maximum value flashes












0














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:



enter image description here



100% image:



enter image description here










share|improve this question





























    0














    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:



    enter image description here



    100% image:



    enter image description here










    share|improve this question



























      0












      0








      0







      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:



      enter image description here



      100% image:



      enter image description here










      share|improve this question















      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:



      enter image description here



      100% image:



      enter image description here







      ios swift uiview uislider






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 13:21









      Kuldeep

      2,47441534




      2,47441534










      asked Nov 12 '18 at 13:16









      netshark1000

      3,49743869




      3,49743869
























          2 Answers
          2






          active

          oldest

          votes


















          0














          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.






          share|improve this answer





















          • 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



















          0














          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)
          }





          share|improve this answer





















          • 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












          • 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










          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          0














          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.






          share|improve this answer





















          • 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
















          0














          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.






          share|improve this answer





















          • 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














          0












          0








          0






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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













          0














          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)
          }





          share|improve this answer





















          • 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












          • 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










          • 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
















          0














          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)
          }





          share|improve this answer





















          • 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












          • 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










          • 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














          0












          0








          0






          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)
          }





          share|improve this answer












          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)
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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










          • 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


















          • 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












          • 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










          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma