1. Create a blank iOS application (empty application).
2. Add the Controller class. Modifying the viewdidload of a controller class
1- (void) Viewdidload2 {3 [Super Viewdidload];4 //Create a title5UILabel *header =[[UILabel alloc] init];6Header.text =@"Welcome to my world!";7Header.textalignment =Nstextalignmentcenter;8 [Self.view Addsubview:header];9 TenSelf.statuslabel =[[UILabel alloc] init]; OneSelf.statusLabel.text =@"Get ready!"; A [Self.view AddSubview:self.statusLabel]; - - the //adding automatic layout constraints -UILabel *statuslabel =Self.statuslabel; - [Header settranslatesautoresizingmaskintoconstraints:no]; - [Statuslabel Settranslatesautoresizingmaskintoconstraints:no]; + -Nsmutablearray *contraits =[Nsmutablearray array]; +Nsmutabledictionary *metrics = [[Nsmutabledictionary alloc] initwithobjectsandkeys:@5,@"hpadding", @5,@"vpadding", @ -,@"TopMargin", nil]; ANsdictionary *views =nsdictionaryofvariablebindings (header, Statuslabel); at[Contraits addobjectsfromarray:[nslayoutconstraint Constraintswithvisualformat:@"h:|-hpadding-[header]-hpadding-|"Options0Metrics:metrics Views:views]]; -[Contraits addobjectsfromarray:[nslayoutconstraint Constraintswithvisualformat:@"h:|-hpadding-[statuslabel]-hpadding-|"Options0Metrics:metrics Views:views]]; -[Contraits arraybyaddingobjectsfromarray:[nslayoutconstraint Constraintswithvisualformat:@"h:|-hpadding-[statuslabel]-hpadding-|"Options0Metrics:metrics Views:views]]; -[Contraits addobjectsfromarray:[nslayoutconstraint Constraintswithvisualformat:@"v:|-topmargin-[header]-(>=0)-[statuslabel]-vpadding-|"Options0Metrics:metrics Views:views]]; - - [Self.view addconstraints:contraits]; in -}
3. Modify the APPDELEGATE.M file
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{ = [[UIWindow alloc ] initwithframe:[[uiscreen mainscreen] bounds]; // Override point for customization after application launch. Self.window.backgroundColor = [Uicolor whitecolor]; // Join the controller Self.window.rootViewController = [[Demoviewcontroller alloc] Initwithnibname:nil Bundle:nil]; [Self.window makekeyandvisible]; return YES;}
4. Run the program to get the following effect