Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UISlider设置最大跟踪颜色_Ios_Objective C_Ios7_Uislider - Fatal编程技术网

Ios UISlider设置最大跟踪颜色

Ios UISlider设置最大跟踪颜色,ios,objective-c,ios7,uislider,Ios,Objective C,Ios7,Uislider,我正在尝试在UISlider上动态配置轨迹颜色 这行代码非常适合设置滑块轨迹的低端 [self.sliderBar setMinimumTrackTintColor:[UIColor redColor]] <Error>: CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context

我正在尝试在UISlider上动态配置轨迹颜色

这行代码非常适合设置滑块轨迹的低端

[self.sliderBar setMinimumTrackTintColor:[UIColor redColor]]

<Error>: CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: clip: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextDrawLinearGradient: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
当尝试对滑块轨迹的高端执行相同操作时,这行代码会向调试日志报告3个致命错误

[self.sliderBar setMaximumTrackTintColor:[UIColor redColor]]

<Error>: CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: clip: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

<Error>: CGContextDrawLinearGradient: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
:CGContextAddPath:无效的上下文0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降级。此通知是出于礼貌:请解决此问题。这将成为即将进行的更新中的致命错误。
:剪辑:无效的上下文0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降级。此通知是出于礼貌:请解决此问题。这将成为即将进行的更新中的致命错误。
:CGContextDrawLinearGradient:无效的上下文0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降级。此通知是出于礼貌:请解决此问题。这将成为即将进行的更新中的致命错误。
我也尝试过使用点表示法设置轨道的色调颜色,但报告了相同的3个错误

self.sliderBar.maximumTrackTintColor=[UIColor redColor]

我很困惑,为什么正确设置了最小轨迹着色颜色,而最大轨迹着色颜色却被破坏了。如蒙协助,将不胜感激


这个问题似乎与这个问题有关,但我不是100%确定,因为我没有处理图形(只设置色调)。这很奇怪,最小值和最大值对我来说都很好,我甚至可以让它设置颜色变化的动画。我所能建议的就是重新创建滑块和@synthesis

@synthesize slider;

- (void)viewDidLoad
{
[super viewDidLoad];
[slider setMinimumTrackTintColor:[UIColor orangeColor]];
[slider setMaximumTrackTintColor:[UIColor blueColor]];



// Do any additional setup after loading the view, typically from a nib.
}

我认为这是苹果公司的问题。有很多人在7.1中报告了奇怪的UISlider行为。我个人无法改变最小的色调。我认为在这一点上你无能为力。

这是一个苹果的bug,它仍然存在于iOS 8中。我在试图通过子类上的代理设置程序修改滑块的最大着色颜色时看到过它。更改最小着色颜色效果良好,不会显示任何错误,但尝试更改最大着色颜色会引发大量糟糕的上下文错误,并且经常将滑块渐变的该部分绘制到错误的位置(这证明它确实没有良好的上下文)


我找不到解决此问题的方法,但将提交错误报告。

避免冗余设置maximumTrackTintColor。当我的代码两次更新颜色时,最大行就会消失。我能够用一个简单的UISlider复制它,如下所示:

    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 150, 23)];
    slider.maximumTrackTintColor = [UIColor whiteColor];
    slider.maximumTrackTintColor = [UIColor whiteColor];
当在iOS 8下的屏幕上显示时,此滑块将没有最大轨迹,而不是白色轨迹。

iOS 8.3
它通过以下方法工作:

[slider setMinimumTrackTintColor:[UIColor orangeColor]];
[slider setMaximumTrackTintColor:[UIColor blueColor]];
或:

编辑

对不起,我在考试时一定是错了。。。但我无法通过界面生成器更改maximumTrackTintColor

如果您想更改UISlider的maximumTrackTintColor请使用上述方法。对我来说,出现问题的原因是,我对
UISlider
进行了子类化,创建了一个自定义的
trackRectForBounds
,它返回的cRect大小无效。我最初的实现(可能还有一些iOS版本的实现?)返回了一个大小为零或负的轨迹边界,具体取决于UISlider的边界。这似乎与设置
minimum
/
maximumtracktingcolor
将调用
trackRectForBounds
有关,可能是为了创建轨迹图像

解决此问题的方法是确保在设置最小/最大轨迹着色颜色时轨迹边界有效

选项1:使用initWithFrame,该框架的大小足以容纳UISlider

UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0,0,100,38)];
slider.minimumTrackTintColor = [UIColor greenColor];
slider.maximumTrackTintColor = [UIColor orangeColor];
// ... rest of view setup ...
选项2:添加滑块并强制自动布局,以便在设置着色颜色之前正确调整大小

UISlider *slider = [[UISlider alloc] init]; // <-- problem, zero size
[view addSubview:slider];
// ... other view setup, including constraints ...
[view layoutIfNeeded]; // forced layout to give slider a non-zero size
slider.minimumTrackTintColor = [UIColor greenColor];
slider.maximumTrackTintColor = [UIColor orangeColor];
注意:我在
viewdiload
so之后创建UISliders
这对我不起作用,但我想这也可以解释。我也猜在大多数情况下可能效果最好。

当您在故事板和代码中同时设置
maximumTrackTintColor
时,这也会重现。我不知道其他iOS版本,但在8.4.1中,检查maximumTrackTintColor的值,并仅在该颜色尚未工作时将其指定给所需颜色。我必须将maximumTrackTintColor设置为我不想要的颜色,然后将其设置为我想要的颜色。使用不等式“if”语句,最大行消失。@VincentDucastel点表示法实际上在幕后调用了同一个setter。除了你传递的颜色,这两个代码片段是等效的。对不起,我在测试中出错了。。。但我不能通过界面生成器更改maximumTrackTintColor。。。。我编辑我的答案。谢谢。点符号实际上在幕后调用同一个setter。除了你传递的颜色,这两个代码片段是等效的。对不起,我在测试中出错了。。。但我不能通过界面生成器更改maximumTrackTintColor。。。。我编辑我的答案。谢谢。我采用的解决方法是创建一个具有所有相同属性的全新UISlider,扔掉原来的,并将新的放在原来的位置。我对一个子类UISlider也有类似的问题。它有一个在initWith*方法中加载的自定义背景。然而,trackRectFor
- (CGRect)trackRectForBounds:(CGRect)bounds {
     // example, inset left/right by 2 (thus width - 4)
     // track height is 5 pixels, centered in bounds.
     return CGRectMake(
         CGRectGetMinX(bounds) + 2,
         CGRectGetMinY(bounds) + (CGRectGetHeight(bounds) + 5)/2.0,
         MAX(10, CGRectGetWidth(bounds) - 4), // use max make sure positive.
         5)
}