/
CustomViewObjetiveC.m
86 lines (68 loc) · 1.96 KB
/
CustomViewObjetiveC.m
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// CustomViewObjetiveC.m
// CustomViewTest
//
// Created by Yume on 2014/6/3.
// Copyright (c) 2014年 yume. All rights reserved.
//
#import "CustomViewObjetiveC.h"
@interface CustomViewObjetiveC(){
dispatch_once_t onceTokenViewLiveRendering;
}
@property (nonatomic,strong) UILabel *label;
@end
@implementation CustomViewObjetiveC
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
-(void)setup{
_label = [UILabel new];
[self addSubview:_label];
self.backgroundColor = [UIColor whiteColor];
}
-(void)prepareForInterfaceBuilder{
[self viewLiveRendering];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
*/
- (void)drawRect:(CGRect)rect{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect myFrame = self.bounds;
// Set the line width to 10 and inset the rectangle by
// 5 pixels on all sides to compensate for the wider line.
CGContextSetLineWidth(context, _lineWidth);
CGRectInset(myFrame, 5, 5);
[_fillColor set];
UIRectFrame(myFrame);
#ifndef TARGET_INTERFACE_BUILDER
[self viewLiveRendering];
#endif
}
-(void)viewLiveRendering{
dispatch_once(&onceTokenViewLiveRendering, ^{
_label.frame = _labelRect;
_label.text = _labelText;
_label.textColor = _labelColor;
});
}
#pragma mark - Custom Quick Look
// OS Types Supporting debugQuickLookObject :
// https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/CustomClassDisplay_in_QuickLook/CH02-std_objects_support/CH02-std_objects_support.html#//apple_ref/doc/uid/TP40014001-CH3-SW1
-(id)debugQuickLookObject{
return self;
}
@end