简体   繁体   English

UISlider自定义图像和拇指高度?

[英]UISlider custom images and thumb height?

I am creating (or attempting to) a custom UISlider look, still horizontal but much taller. 我正在创建(或尝试)自定义UISlider外观,该外观仍为水平但更高。 I have two problems. 我有两个问题。

1.This is the code I'm using to get the images onto the slider. 1.这是我用来将图像放到滑块上的代码。

UIImage *minImage = [UIImage imageNamed:@"sliderMin.png"];
UIImage *maxImage = [UIImage imageNamed:@"sliderMax.png"];
UIImage *thumbImage = [UIImage imageNamed:@"sliderThumb.png"];

minImage = [minImage stretchableImageWithLeftCapWidth:33.0 topCapHeight:0.0];
maxImage = [maxImage stretchableImageWithLeftCapWidth:33.0 topCapHeight:0.0];
// thumbImage = [minImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];

[_contrastSlider setMinimumTrackImage:minImage forState:UIControlStateNormal];
[_contrastSlider setMaximumTrackImage:maxImage forState:UIControlStateNormal];
[_contrastSlider setThumbImage:thumbImage forState:UIControlStateNormal];

minImage = nil;
maxImage = nil;
thumbImage = nil;

[_contrastSlider setMinimumValue:0.0];
[_contrastSlider setMaximumValue:100.00];
[_contrastSlider setValue:25.0];

I have three images, min, max and thumb. 我有三个图像,最小,最大和拇指。 These are the images and how they look on the device, which isn't correct. 这些是图像以及它们在设备上的外观,这是不正确的。

I can't post images yet, so here is a link to MYSlider.jpeg which shows the components. 我还不能发布图片,因此这里是显示组件的MYSlider.jpeg链接

The slider should be cream to the right of the thumb, pink to the left. 滑块应在拇指的右侧为奶油,左侧为粉红色。 But this isn't happening. 但是,这没有发生。

That's problem 1. Problem 2 is the thumb size default is too small. 那是问题1。问题2是拇指大小的默认值太小。 I'm using this : UISlider Height Hack to try to increase the height of the thumb, but sadly it's making it wider not taller. 我正在使用: UISlider Height Hack尝试增加拇指的高度,但可悲的是它使宽度变大而不是变高。 So I am asking for help to make the area taller, not wider, and wondering why my pink image is being ignored? 因此,我正在寻求帮助以使该区域更高而不是更宽,并且想知道为什么我的粉红色图像被忽略了吗?

Thank you for any help. 感谢您的任何帮助。

If it helps, here is my UISlider subclass .m: 如果有帮助,这是我的UISlider子类.m:

-(BOOL) pointInside:(CGPoint)point withEvent:(UIEvent*)event {
CGRect bounds = self.bounds;
bounds = CGRectInset(bounds, -10, -8);
return CGRectContainsPoint(bounds, point);

} }

-(BOOL) beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
  CGRect bounds = self.bounds;
  float thumbPercent = (self.value - self.minimumValue) / (self.maximumValue - self.minimumValue);
  float thumbPos = THUMB_SIZE + (thumbPercent * (bounds.size.width - (2 * THUMB_SIZE)));
  CGPoint touchPoint = [touch locationInView:self];
  return (touchPoint.x >= (thumbPos - EFFECTIVE_THUMB_SIZE) && touchPoint.x <= (thumbPos + EFFECTIVE_THUMB_SIZE));
}

Thank you. 谢谢。

It turns out setting my slider values in the views did load method was causing problems. 原来在加载方法导致问题的视图中设置我的滑块值。 I set them in Interface Builder and that was fixed. 我在Interface Builder中设置了它们,此问题已得到解决。 Once set in IB I can tweak them in code if needs be with no problems. 一旦在IB中设置,如果需要,我可以在代码中对其进行调整。

As for my other problem, I'm wondering if this is because I'm not testing on an actual device, so I'm going to pause that question until I get it on the device in a few weeks. 至于我的其他问题,我想知道这是否是因为我没有在实际设备上进行测试,所以我将暂停该问题,直到几周后在设备上得到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM