应使用故事板创建用于在点击地图图钉上显示的自定义视图。 可以在场景内的View控制器外部创建自定义视图。 但是,应该在使用地图控件的所有其他视图控制器上创建单个自定义视图。
How to create a custom view(width:300, height:150) on storyboard and that created view can be used on other view controller also?
请建议......
答案 0 :(得分:0)
在XIB中构建UIView我想,创建基类whit访问从XIB唤醒此视图并将其添加为子视图。
从XIB加载视图,您可以使用UIView类别(名称XIB与类名相同):
@implementation UIView (NIB)
+ (id)loadFromNIBWithName:(NSString *)aName {
Class klass = [self class];
NSArray* objects = [[NSBundle mainBundle] loadNibNamed:aName owner:self options:nil];
for (id object in objects) {
if ([object isKindOfClass:klass]) {
return object;
}
}
[NSException raise:@"WrongNibFormat" format:@"Nib for '%@' must contain one UIView, and its class must be '%@'", aName, NSStringFromClass(klass)];
return nil;
}
+ (UIView *)loadFromNIBWithName:(NSString *)aName frame:(CGRect)aFrame {
UIView *v = (UIView *)[self loadFromNIBWithName:aName];
v.frame = aFrame;
return v;
}
+ (id)loadFromNIB {
return [self loadFromNIBWithName:[self nibName]];
}
+ (UIView *)loadFromNIBWithFrame:(CGRect)aFrame {
UIView *v = (UIView *)[self loadFromNIB];
v.frame = aFrame;
return v;
}
+ (NSString*)nibName {
return NSStringFromClass([self class]);
}
@end
您可以使用视图创建UIViewController
的另一个解决方案,为其创建自定义segue,覆盖- (void)perform
方法以从destinationViewController
获取视图并输入sourceViewController.view
< / p>