iphone - UISlider minimumValueImageRectForBounds : and super maximumValueImageRectForBounds returns empty rectangle

标签 iphone objective-c ios cocoa-touch uislider

我将 UISlider 子类化以使拇指变小,并且我想覆盖 minimumValueImageRectForBoundsmaximumValueImageRectForBounds 以使其宽度减少 2px。所以我的代码是

- (CGRect)minimumValueImageRectForBounds:(CGRect)bounds
{
    CGRect stdRect = [super minimumValueImageRectForBounds:bounds];
    return CGRectMake(stdRect.origin.x + 2, stdRect.origin.y, stdRect.size.width - 2, stdRect.size.height);
}

重点是 stdRect 是空矩形 (0, 0, 0, 0)。

此外,如果我明确地设置一些像那样的矩形

- (CGRect)minimumValueImageRectForBounds:(CGRect)bounds
{
    return CGRectMake(2, 0, 40, 8);
}

它根本不影响最小值图像位置。

有什么想法吗?

最佳答案

哈哈,我刚刚弄明白了。我没有仔细阅读。

设置 minimumValueImage 与调用 setMinimumTrackImage:forState: 不同。 minimumValueImage 是显示在 slider 左侧的图像,与 slider 中发生的事情无关。重写 minimumValueImageRectForBounds 会更改此图像的尺寸(默认大小为 0pt 宽), slider 框架的宽度会变小并因此向右移动。据我了解,没有办法修改 minimumTrackImage 的矩形(例如使其延伸到拇指图像的右侧);只能更改图像。

我还没有真正弄清楚允许您设置 minimumValueImage 的意义。看起来您可以通过更改 slider 的大小并将单独的 UIImageView 添加到 slider 的一侧来完成相同的事情。谁知道。

请注意,我在这里所说的一切都以相同的方式适用于 maximumValueImagesetMaximumTrackImage:forState 方法。

关于iphone - UISlider minimumValueImageRectForBounds : and super maximumValueImageRectForBounds returns empty rectangle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9564708/

相关文章:

iOS7 崩溃 - PopViewController 在 Landscape ViewController 上调用

ios - 使用 PHP 从 Swift 连接到在线数据库 (mySQL)。 (X代码)

ios - 在 Objective-c 中使用通用扩展 swift 类

ios - 在 ASIFormDataRequest iOS dev 中获取异步响应和同步调用超时

iphone - Objective-C 输出流刷新问题?

iphone - 适用于 iPhone/iPad 的 VPN 客户端

objective-c - 不同类中的同名实例变量导致编译错误

javascript - jQuery 对话框上的 onclick 事件不适用于 IOS

ios - XMPP 聊天应用程序因使用 VoIP 服务作为后台模式而被拒绝

ios - 我们是否必须在 UIViewController 中的 viewDidLoad 中或 viewDidLoad 之外初始化属性?