<i id='gj2DF'><tr id='gj2DF'><dt id='gj2DF'><q id='gj2DF'><span id='gj2DF'><b id='gj2DF'><form id='gj2DF'><ins id='gj2DF'></ins><ul id='gj2DF'></ul><sub id='gj2DF'></sub></form><legend id='gj2DF'></legend><bdo id='gj2DF'><pre id='gj2DF'><center id='gj2DF'></center></pre></bdo></b><th id='gj2DF'></th></span></q></dt></tr></i><div id='gj2DF'><tfoot id='gj2DF'></tfoot><dl id='gj2DF'><fieldset id='gj2DF'></fieldset></dl></div>

    1. <small id='gj2DF'></small><noframes id='gj2DF'>

    2. <legend id='gj2DF'><style id='gj2DF'><dir id='gj2DF'><q id='gj2DF'></q></dir></style></legend>
    3. <tfoot id='gj2DF'></tfoot>
      • <bdo id='gj2DF'></bdo><ul id='gj2DF'></ul>

      将 TintColor 设置为 MKAnnotationView 图像

      时间:2024-04-14

      • <legend id='fL7gK'><style id='fL7gK'><dir id='fL7gK'><q id='fL7gK'></q></dir></style></legend>
            <tbody id='fL7gK'></tbody>
          <tfoot id='fL7gK'></tfoot>
          <i id='fL7gK'><tr id='fL7gK'><dt id='fL7gK'><q id='fL7gK'><span id='fL7gK'><b id='fL7gK'><form id='fL7gK'><ins id='fL7gK'></ins><ul id='fL7gK'></ul><sub id='fL7gK'></sub></form><legend id='fL7gK'></legend><bdo id='fL7gK'><pre id='fL7gK'><center id='fL7gK'></center></pre></bdo></b><th id='fL7gK'></th></span></q></dt></tr></i><div id='fL7gK'><tfoot id='fL7gK'></tfoot><dl id='fL7gK'><fieldset id='fL7gK'></fieldset></dl></div>

          1. <small id='fL7gK'></small><noframes id='fL7gK'>

              • <bdo id='fL7gK'></bdo><ul id='fL7gK'></ul>

                本文介绍了将 TintColor 设置为 MKAnnotationView 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在为 iOS 7.0+ 编写一个应用程序,我想使用新功能:imageWithRenderingMode.我有一个带有此代码的地图注释:

                I'm writing an application for iOS 7.0+ and I wanted to use new feature witch is: imageWithRenderingMode. I have a map annotation with this code:

                -(MKAnnotationView*)annotationView {
                    MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:self reuseIdentifier:@"AnnotationIdentifier"];
                    annotationView.enabled = YES;
                    annotationView.canShowCallout = YES;
                    annotationView.image = [[UIImage imageNamed:@"star"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
                    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                    annotationView.tintColor = [UIColor redColor];
                    return annotationView;
                }
                

                我预计我的图钉会是红色的,但保持黑色,只有标注 (i) 图标变为红色.

                I was expected that my pins will be red, but stays black, only the callout (i) icon turns red.

                我试图在我的 ViewController 中设置 self.view.tintColorself.mapView.tintColor 但这也不起作用.如何将这个引脚变成红色?

                I was trying to set self.view.tintColor and self.mapView.tintColor in my ViewController but this not working either. How to turns this pins red?

                推荐答案

                有一个比不涉及创建 UIImageView 的提议更好的解决方案.

                There's a better solution than those proposed that doesn't involve creating a UIImageView.

                此 Swift 代码将创建您的 UIImage 的彩色版本.

                This Swift code will create a colored version of your UIImage.

                extension UIImage {
                
                    func colorized(color : UIColor) -> UIImage {
                        let rect = CGRectMake(0, 0, self.size.width, self.size.height);
                        UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0);
                        let context = UIGraphicsGetCurrentContext();
                        CGContextSetBlendMode(context, .Multiply)
                        CGContextDrawImage(context, rect, self.CGImage)
                        CGContextClipToMask(context, rect, self.CGImage)
                        CGContextSetFillColorWithColor(context, color.CGColor)
                        CGContextFillRect(context, rect)
                        let colorizedImage = UIGraphicsGetImageFromCurrentImageContext();
                        UIGraphicsEndImageContext();
                        return colorizedImage
                    }
                }
                

                这样称呼它:

                UIImage(named: "myImage")!
                    .imageWithRenderingMode(.AlwaysTemplate)
                    .colorized(UIColor.red())
                

                这篇关于将 TintColor 设置为 MKAnnotationView 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:你如何知道在 touchesBegan 中被触摸的对象是什么? 下一篇:在 UIImageView 中显示隔行(逐行)图像

                相关文章

                <small id='Ey3Jf'></small><noframes id='Ey3Jf'>

                  <bdo id='Ey3Jf'></bdo><ul id='Ey3Jf'></ul>
                <tfoot id='Ey3Jf'></tfoot>

                  <legend id='Ey3Jf'><style id='Ey3Jf'><dir id='Ey3Jf'><q id='Ey3Jf'></q></dir></style></legend>
                    <i id='Ey3Jf'><tr id='Ey3Jf'><dt id='Ey3Jf'><q id='Ey3Jf'><span id='Ey3Jf'><b id='Ey3Jf'><form id='Ey3Jf'><ins id='Ey3Jf'></ins><ul id='Ey3Jf'></ul><sub id='Ey3Jf'></sub></form><legend id='Ey3Jf'></legend><bdo id='Ey3Jf'><pre id='Ey3Jf'><center id='Ey3Jf'></center></pre></bdo></b><th id='Ey3Jf'></th></span></q></dt></tr></i><div id='Ey3Jf'><tfoot id='Ey3Jf'></tfoot><dl id='Ey3Jf'><fieldset id='Ey3Jf'></fieldset></dl></div>