The principle of implementation: the use of automatic layout and deformation
Core code block:
@implementation Jhmainview
{
UILabel *label1,*label2,*label3,*label4;
UIButton *btn;
}
-(ID) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self) {
BTN = [[UIButton alloc]initwithframe:cgrectmake (100, 120, 120, 120)];
Btn.transform = Cgaffinetransformrotate (Btn.transform, m_pi_4);
[Btn addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside];
Btn.autoresizessubviews = YES;
Btn.backgroundcolor = [Uicolor Cyancolor];
Label1 = [[UILabel alloc]initwithframe:cgrectmake (0, 0, 60, 60)];
Label1.backgroundcolor = [Uicolor Orangecolor];
Label2 = [[UILabel alloc]initwithframe:cgrectmake (BTN.BOUNDS.SIZE.WIDTH/2, 0, 60, 60)];
Label2.autoresizingmask = Uiviewautoresizingflexibleleftmargin;
Label2.backgroundcolor = [Uicolor blackcolor];
Label3 = [[UILabel alloc]initwithframe:cgrectmake (0, BTN.BOUNDS.SIZE.HEIGHT/2, 60, 60)];
Label3.backgroundcolor = [Uicolor Bluecolor];
Label3.autoresizingmask = Uiviewautoresizingflexibletopmargin;
Label4 = [[UILabel alloc]initwithframe:cgrectmake (BTN.BOUNDS.SIZE.WIDTH/2, BTN.BOUNDS.SIZE.HEIGHT/2, 60, 60)];
Label4.autoresizingmask = Uiviewautoresizingflexibletopmargin | Uiviewautoresizingflexibleleftmargin;
Label4.backgroundcolor = [Uicolor Purplecolor];
[Btn Addsubview:label1];
[Btn Addsubview:label2];
[Btn Addsubview:label3];
[Btn Addsubview:label4];
[Self addsubview:btn];
}
return self;
}
-(void) Btnclick: (UIButton *) sender
{
static int i=1;
Btn.center = Btn.center;
if (i%2)
{
Btn.bounds = CGRectMake (0, 0, 180, 180);
}
Else
{
Btn.bounds = CGRectMake (0, 0, 120, 120);
}
i++;
}
@end