summaryrefslogtreecommitdiff
path: root/platform/ios/src/UIImage+MGLAdditions.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/src/UIImage+MGLAdditions.mm')
-rw-r--r--platform/ios/src/UIImage+MGLAdditions.mm18
1 files changed, 17 insertions, 1 deletions
diff --git a/platform/ios/src/UIImage+MGLAdditions.mm b/platform/ios/src/UIImage+MGLAdditions.mm
index 884f92e003..9d05abd6ca 100644
--- a/platform/ios/src/UIImage+MGLAdditions.mm
+++ b/platform/ios/src/UIImage+MGLAdditions.mm
@@ -1,7 +1,10 @@
#import "UIImage+MGLAdditions.h"
+#import "NSBundle+MGLAdditions.h"
#include <mbgl/util/image+MGLAdditions.hpp>
+const MGLExceptionName MGLResourceNotFoundException = @"MGLResourceNotFoundException";
+
@implementation UIImage (MGLAdditions)
- (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)styleImage
@@ -42,7 +45,20 @@
float(self.scale), isTemplate);
}
--(mbgl::PremultipliedImage)mgl_premultipliedImage {
+- (mbgl::PremultipliedImage)mgl_premultipliedImage {
return MGLPremultipliedImageFromCGImage(self.CGImage);
}
+
++ (UIImage *)mgl_resourceImageNamed:(NSString *)imageName {
+ UIImage *image = [UIImage imageNamed:imageName
+ inBundle:[NSBundle mgl_frameworkBundle]
+ compatibleWithTraitCollection:nil];
+
+ if (!image) {
+ [NSException raise:MGLResourceNotFoundException format:@"The resource named “%@” could not be found in the Mapbox framework bundle.", imageName];
+ }
+
+ return image;
+}
+
@end