I've found this code on this blog http://themainthread.com/blog/2014/02/building-a-universal-app.html
static void initSimpleView(SimpleView *self) {
// Configure default properties of your view and initialize any subviews
self.backgroundColor = [UIColor clearColor];
self.imageView = ({
UIImageView *imageView = [[UIImageView alloc] init];
imageView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:imageView];
imageView;
});
self.label = ({
UILabel *label = [[UILabel alloc] init];
label.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:label];
label;
});
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
initSimpleView(self);
}
return self;
}
How does it work?
What is the meaning of static void initWithSimpleView(SimpleView *self)
?
Why are imageView
and label
initialized in some kind of block?