Skip to content

Instantly share code, notes, and snippets.

@folex
Created April 8, 2014 11:37
Show Gist options
  • Save folex/10112592 to your computer and use it in GitHub Desktop.
Save folex/10112592 to your computer and use it in GitHub Desktop.
UIView category to add multiple subviews at once
//.h
@interface UIView (AddSubviews)
- (void) addSubviews:(UIView*) subview1, ...
NS_REQUIRES_NIL_TERMINATION;
@end
//.m
@implementation UIView (AddSubviews)
- (void)addSubviews:(UIView *)subview1, ... {
va_list subviews;
va_start(subviews, subview1);
for (UIView *subview = subview1; subview != nil; subview = va_arg(subviews, UIView*)) {
[self addSubview:subview];
}
va_end(subviews);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment