我基于此代码:Custom MKAnnotationView with frame,icon and image
而且我正在尝试做一些不同的事情......我有一个不透明的图像,我想在里面放一个图像。我的问题是背景图像覆盖了我的图像。所以它看起来像:http ://cl.ly/image/0E0S00072G1n
我的代码是这样的:
annotationImageView.image = [UIImage imageNamed:@"marker_fb"];
UIImage *frame = [UIImage imageNamed:@"marker_fb"];
ImagePin *imagePinImage = annotation;
NSString *urlStringForImage = [NSString stringWithFormat:@"%@", imagePinImage.image];
NSURL *urlForImage = [NSURL URLWithString:urlStringForImage];
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", urlForImage]] placeholderImage:[UIImage imageNamed:@"avatar-placeholder.png"]];
UIGraphicsBeginImageContext(CGSizeMake(annotationImageView.image.size.width, annotationImageView.image.size.height));
[frame drawInRect:CGRectMake(0, 0, frame.size.width, frame.size.height)];
[imageView.image drawInRect:CGRectMake(2, 2, 48, 38)]; // the frame your inner image
annotationImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
z-indez 是否存在于 object-c 中?或者我该怎么办?谢谢。 编辑:我也尝试过:
UIGraphicsBeginImageContextWithOptions(CGSizeMake(annotationImageView.image.size.width, annotationImageView.image.size.height), NO, 0);