Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Allow non-template Images or Access to the ImageView in some way #19

Closed
tysonkerridge opened this issue Mar 24, 2016 · 1 comment

Comments

@tysonkerridge
Copy link

Correct me if I'm wrong, but whenever an image is set to the SVPulsingAnnotationView, it is set to the private imageView with the UIImageRenderingModeAlwaysTemplate Rendering Mode and uses the annotationColor as the tintColor of that imageView (Lines 152 and 165 of SVPulsingAnnotationView.m as of this commit - 29th July 2015). This means if, for example, the annotation's pulse color was to be the default blue, but the image was a different color, say red, it would always render as blue.

It would be nice if the image could be set to the imageView as the actual image set to that property. Alternatively, as it's already using UIImageRenderingModeAlwaysTemplate as default, a BOOL property could be added to the class such as setImagesAsTemplate which defaults to YES and then wherever images are being added, that Boolean could be used to determine whether to set the image as Template or not. Doing this would mean any previous users wouldn't have to do anything and this issue would be fixed.

I think that #15 (image stays behind the dot) may possibly be referring to this issue but #15 is very vague. I might create a Pull Request with the above proposed changes in the next few days but for now my work around in a subclass is as follows overriding two methods:

- (void)willMoveToSuperview:(UIView *)newSuperview {

    // Set an image so that when it rebuilds the layers it will add the Image View
    self.image = [UIImage imageNamed:@"empty"]; // This is an actual image named empty

    // Call Super which rebuilds the layers and adds the image view because there's an image set to the image property
    [super willMoveToSuperview:newSuperview];

    // Set the image we want
    self.image = [UIImage imageNamed:@"imageWeWant"]; // The image we actually want to set to the imageView

}

- (void)setImage:(UIImage *)image {

    // Call super so that it sets the image
    [super setImage:image];

    // Now we want to set the image to the image view ourselves, as the superclass calls `imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate` on the image
    for (UIView *subview in self.subviews) {
        // Should only be one subview, but make sure it's the image view
        if ([subview isKindOfClass:[UIImageView class]]) {
            // Set the image
            ((UIImageView *)subview).image = image;
            break; // Just incase there are other subviews, we don't care at this point.
        }
    }

}

This sets the image called imageWeWant to the imageView in the setImage: method by scanning the subviews for an imageView and setting that image to the imageView's image property without any other rendering. The setImage: method would get called for the empty image also, though at that point there doesn't seem to be an imageView in the subviews, and instead just allows for the imageView to be added when rebuildLayers is called within the super (SVPulsingAnnotationView) implementation of willMoveToSuperview:.

TL;DR:
The Above Block of code is a workaround for this issue. Will attempt the proposed changes in the second paragraph (not the above block of code) and create a Pull Request soon to hopefully fix the issue.

Hopefully I haven't missed something which is already implemented to help this issue. Let me know :).

tysonkerridge added a commit to tysonkerridge/SVPulsingAnnotationView that referenced this issue Mar 25, 2016
…the imageView and headingImageView to be set as is instead of with the UIImageRenderingModeAlwaysTemplate Rendering Mode. Defaults to YES as to not change anything for those who would update to this commit and still want the Rendering Mode defaulting to Template. Fixes issue TransitApp#19 on SVPulsingAnnotationView.
@tysonkerridge
Copy link
Author

tysonkerridge commented Mar 25, 2016

The Above reference to #20 (Allows fix for issue #19 where Images set are always Template.) will fix this issue. Going to close this Issue.

If the #20 Pull request doesn't get merged, feel free to use it from my Fork.
Using Pods, add this to your PodFile:
pod 'SVPulsingAnnotationView', :git => 'https://github.com/tysonkerridge/SVPulsingAnnotationView.git', :commit => '4eb41827a4c8b7746b2997f967764e1b2442bb6e', :branch => 'nontemplate-images'

tysonkerridge added a commit to tysonkerridge/SVPulsingAnnotationView that referenced this issue Apr 13, 2017
…the imageView and headingImageView to be set as is instead of with the UIImageRenderingModeAlwaysTemplate Rendering Mode. Defaults to YES as to not change anything for those who would update to this commit and still want the Rendering Mode defaulting to Template. Fixes issue TransitApp#19 on SVPulsingAnnotationView.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant