【发布时间】:2012-10-23 05:41:29
【问题描述】:
self.refreshControl.tintColor = [UIColor blueColor];//this just only change it color
我可以将下拉箭头更改为某些图片或其他形状吗?怎么样?
非常感谢!
【问题讨论】:
标签: ios6 uirefreshcontrol
self.refreshControl.tintColor = [UIColor blueColor];//this just only change it color
我可以将下拉箭头更改为某些图片或其他形状吗?怎么样?
非常感谢!
【问题讨论】:
标签: ios6 uirefreshcontrol
不。您只能更改箭头的颜色,但不能更改箭头本身。如果您希望能够这样做,请file an enhancement request 我们会考虑。
当然,您也可以自己编写一个,或使用开源变体。
【讨论】:
隐藏的 API 版本(在我的实际代码中,maskImage 是 UIImage 上的一个类别)。不知道苹果会不会拒绝这个。
static UIImage *maskImage(UIImage *image, UIColor *color) {
UIImage *retval;
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
[color set];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
[image drawAtPoint:CGPointZero blendMode:kCGBlendModeDestinationIn alpha:1];//
retval = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return retval;
}
@protocol UIRefreshHacking <NSObject>
-(UIImageView*)arrow;
@end
@interface UIRefreshControl (GetAtContentView)
-(UIView<UIRefreshHacking>*)_contentView;
@end
@implementation UIRefreshControl (ChangeArrowColor)
-(BOOL)setArrowColor:(UIColor *)arrowColor {
if(![self respondsToSelector:@selector(_contentView)]) {
return NO;
}
UIView<UIRefreshHacking> *cv = [self _contentView];
if(![cv respondsToSelector:@selector(arrow)]) {
return NO;
}
UIImageView *iv = [cv arrow];
iv.image = maskImage(iv.image, arrowColor);
return YES;
}
@end
【讨论】:
UIRefreshControl 的实现细节,这些细节在未来的任何时候都会发生变化。唯一可以保证的是 API 将保持一致。
_contentView 方法,您很可能会因为UIRefreshControl 类别而被拒绝。
UIRefreshControl,我个人不喜欢看到我的代码被这样滥用。 :)