iOS REMOVE ALL SUBVIEWS
Objective C:
To remove all subViews
# pragma mark - Removing all subviews
- (void) clearAction {
NSLog(@"clear all subViews");
[self.view.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)];
}
or
# pragma mark - Removing all subviews
- (void) clearAction{
for (UIView *subview in self.view.subviews) {
[subview removeFromSuperview];
}
}
To remove particular subview
Swift:
To remove all subViews
//MARK: Removing all subviews
func clearAction() {
self.view.subviews.forEach { subview in
subview.removeFromSuperview()
}
}
or
//MARK: Removing all subviews
func clearAction() {
for subView in self.view.subviews {
subView.removeFromSuperview()
}
}
To remove particular subview
Let's grow together 🌱
Cheers 🍻