iOS 7.1中的UISlider setMaximumTrackTintColor [英] UISlider setMaximumTrackTintColor in iOS 7.1
问题描述
[slider setMaximumTrackTintColor: color]
在iOS 7.1中产生了意外的结果(滑块更改了其位置,而不是垂直居中显示在顶部,或者完全消失了),而在以前的版本中效果很好.
has unexpected results in iOS 7.1 (the slider bar changes its position appearing at top instead of vertical center or disappears completely), while working fine with prior versions.
[slider setMinimumTrackTintColor: color]
呈现预期的结果.
该问题可能与以下问题有关: UISlider setMaximumTrackTintColor , 但到目前为止还没有答案.
This question might be related: UISlider setMaximumTrackTintColor, but no answer so far.
更新:
我得到了:而不是:
更新#2:
使用setMaximumTrackImage
可能有效,但是我正在寻找的解决方案是一种设置任何随机颜色而不是预先存在的图像的方法.
Using setMaximumTrackImage
might work, but the solution I'm looking for is a way to set any random color and not a preexisting image.
更新#3:
iOS 7.1.1 中仍然存在此问题.
推荐答案
发现了此工作方式:
动态地从UIColor
创建1x1px UIImage
:
Create a 1x1px UIImage
from a UIColor
on the fly:
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
然后
[slider setMaximumTrackImage:image forState:UIControlStateNormal];
看起来像一个昂贵的解决方案,但它可以完成工作.
Looks like an expensive solution but it gets the job done.
这篇关于iOS 7.1中的UISlider setMaximumTrackTintColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!