【问题标题】:About UIRefreshControl How to change the default pull down arrow in IOS6.0关于UIRefreshControl IOS6.0如何更改默认下拉箭头
【发布时间】:2012-10-23 05:41:29
【问题描述】:
self.refreshControl.tintColor = [UIColor blueColor];//this just only change it color

我可以将下拉箭头更改为某些图片或其他形状吗?怎么样?

非常感谢!

【问题讨论】:

    标签: ios6 uirefreshcontrol


    【解决方案1】:

    不。您只能更改箭头的颜色,但不能更改箭头本身。如果您希望能够这样做,请file an enhancement request 我们会考虑。

    当然,您也可以自己编写一个,或使用开源变体。

    【讨论】:

    • 是的,谢谢 ....一些开源软件好用,支持左右拖拽,谢谢
    【解决方案2】:

    隐藏的 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 将保持一致。
    • 它不会崩溃。发生的最糟糕的情况是 Apple 更改了某些内容,而您的箭头颜色错误 - 很有可能,届时他们将有一个 API 来执行此操作。
    • 如果使用_contentView 方法,您很可能会因为UIRefreshControl 类别而被拒绝。
    • 如果您认为它们是缺点,那么您肯定已经filed an enhancement request 要求解决它们。错误编号是多少?我想跟踪它的进度。当然,欢迎您在代码中做任何您想做的事情。但是我写了UIRefreshControl,我个人不喜欢看到我的代码被这样滥用。 :)
    • 根据经验,我发现不使用官方 API 做事最终会很痛苦。这意味着有时会做不那么理想的事情。就像滥用你的代码一样。 :) 我没有提交很多增强请求,因为它们通常对我来说并不那么重要。出于哲学原因,我们甚至没有在工作中使用 UIRefreshControl,所以它不在我的控制范围内。所以这纯粹是一种娱乐活动。不过,关于 API 决策,我很乐意与您讨论 UIRefreshControl 的理念。
    猜你喜欢
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多