自定义UISlider-增加“热点"尺寸 [英] Custom UISlider - Increase "hot spot" size

查看:103
本文介绍了自定义UISlider-增加“热点"尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的UISlider,由于拇指图像"的大小,对于手指宽大的人来说要抓握并滑动相对较困难.有什么方法可以增加可点击/可拖动区域的大小而不改变图像的大小吗?

I have a custom UISlider that is relatively tough for big fingered people to grab hold of and slide due to the size of the "thumb image". Is there any way to increase the size of clickable / draggable area without altering the size of the image?

这是创建自定义滑块的代码,如果有帮助的话:

Here's the code I have for creating the custom slider if that helps:

[slider setMaximumTrackImage:[[UIImage imageNamed:@"max.png"]
                                             resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)]
                                   forState:UIControlStateNormal];
[slider setMinimumTrackImage:[[UIImage imageNamed:@"min.png"]
                                             resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)]
                                   forState:UIControlStateNormal];
[slider setThumbImage:[UIImage imageNamed:@"thumb.png"]
                            forState:UIControlStateNormal];

推荐答案

我最终继承了UISlider的子类并覆盖了此方法:

I ended up subclassing the UISlider and overriding this method:

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

这会将可触摸区域扩大了左右10个像素,顶部和底部15个像素.

This extends the touchable area by 10 pixels on the left and right and 15 pixels on the top and bottom.

这篇关于自定义UISlider-增加“热点"尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆