Contents
  1. 1. Border
  2. 2. How Border works
  3. 3. Reference

On Android, we have an option called Show layout bounds, which allows us to see bounding areas of your views displayed in vibrant blue and purple.

Border

On iOS, with the help of runtime, we can do the same. Using Border

All you have to do is

1
pod 'Border', '~> 1.0'

How Border works

The idea is to swizzle didMoveToSuperview in constructor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
static void swizzleInstanceMethod(Class class, SEL originalAction, SEL swizzledAction) {
method_exchangeImplementations(class_getInstanceMethod(class, originalAction),
class_getInstanceMethod(class, swizzledAction));
}

static void swizzle() {
swizzleInstanceMethod(UIView.class, @selector(didMoveToSuperview),
@selector(ftg_didMoveToSuperview));
}

__attribute__((constructor)) static void FTGBorderConstructor(void) {
@autoreleasepool {
swizzle();
}
}

#pragma mark - UIView
@interface UIView (FTGBorder)
@end

@implementation UIView (FTGBorder)

- (void)ftg_didMoveToSuperview {
self.layer.borderWidth = 1;
self.layer.borderColor = [UIColor brownColor].CGColor;

[self ftg_didMoveToSuperview];
}

@end

Reference

Contents
  1. 1. Border
  2. 2. How Border works
  3. 3. Reference