First lesson
Ui-uiview Parent-Child Class View auto-scaling
#import "XGOAppDelegate.h"
@implementation Xgoappdelegate
{
UIView *_backview;
}
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
Self.window = [[Uiwindowalloc] initwithframe:[[uiscreenmainscreen] bounds];
UIView *view1 = [[UIView alloc] init];
View1.frame = CGRectMake (10, 30, 300, 30);
View1.backgroundcolor = [Uicolor Redcolor];
[Self.window Addsubview:view1];
UIView *view2 = [[UIView alloc] init];
View2.frame = CGRectMake (5, 5, 100, 20);
View2.backgroundcolor = [Uicolor Yellowcolor];
[View1 ADDSUBVIEW:VIEW2];
UIView *VIEW3 = [[UIView alloc] init];
View3.frame = CGRectMake (100, 5, 100, 20);
View3.backgroundcolor = [Uicolor Bluecolor];
[View1 ADDSUBVIEW:VIEW3];
Get the parent Class View, where View2, VIEW3 is equivalent to the subclass view, View1 is equivalent to the parent Class View
UIView *superview = View2.superview;
Sets the parent view (view1) background color to Black
Superview.backgroundcolor = [Uicolor blackcolor];
Get an array of sub-class views
Nsarray *subviews = view1.subviews;
NSLog (@ "Count =%d", subviews.count);
VIEW2,VIEW3 turned red.
For (UIView *view in subviews) {
View.backgroundcolor = [Uicolor Redcolor];
// }
UIView *view = [Subviews objectatindex:0];
View.backgroundcolor = [Uicolor Redcolor];
UIView *blueview = [[UIView alloc] init];
Blueview.frame = CGRectMake (10, 100, 300, 30);
Blueview.backgroundcolor = [Uicolorbluecolor];
If the child view is higher than the parent view, the Clipstobounds property is available: Yes handling
Blueview.clipstobounds = YES;
[Self.window Addsubview:blueview];
UIView *greenview = [[UIView alloc] init];
Greenview.frame = CGRectMake (10, 5, 200, 100);
Greenview.backgroundcolor = [Uicolor Greencolor];
Set the transparency, the smaller the number, the higher the transparency
Greenview.alpha = 0.5;
[Blueview Addsubview:greenview];
Automatic layout
_backview = [[UIView alloc] init];
_backview.frame = CGRectMake (100, 300, 120, 120);
_backview.backgroundcolor = [Uicolor blackcolor];
Allow sub-Class View auto layout
_backview.autoresizessubviews = YES;
[Self.windowaddsubview:_backview];
UIView *topview = [[UIView alloc] init];
Topview.frame = CGRectMake (10, 10, 100, 100);
Topview.backgroundcolor = [Uicolor Orangecolor];
Set Automatic layout width as the parent class automatically increases
Topview.autoresizingmask = Uiviewautoresizingflexiblewidth;
If width and height are added at the same time or | Said
Topview.autoresizingmask = Uiviewautoresizingflexiblewidth | Uiviewautoresizingflexibleheight;
[_backview Addsubview:topview];
[Nstimerscheduledtimerwithtimeinterval:0.5target:selfselector: @selector (Timetick) UserInfo:nilrepeats:YES];
Override point for customization after application launch.
Self.window.backgroundColor = [Uicolor Whitecolor];
[Self.windowmakekeyandvisible];
Returnyes;
}
-(void) Timetick
{
_backview.frame = CGRectMake (_backview.frame.origin.x, _BACKVIEW.FRAME.ORIGIN.Y, _backview.frame.size.width+5, _ BACKVIEW.FRAME.SIZE.HEIGHT+5);
}
@end
iOS Development Basics