The effect is as follows:
ViewController.h
1 #import <UIKit/UIKit.h>23@interface viewcontroller: Uiviewcontroller4 @property (Strong, Nonatomic) UILabel *lblmessage; 5 @property (Strong, Nonatomic) UILabel *lbldescription; 6 7 @end
Viewcontroller.m
1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 @end5 6 @implementationViewcontroller7 8- (void) Viewdidload {9 [Super Viewdidload];Ten OneSelf.title =@"Adjust"; ASelf.view.backgroundColor =[Uicolor Blackcolor]; -_lbldescription = [[UILabel alloc] Initwithframe:cgrectmake ( -, -, the, -)]; -_lbldescription.text =@"Default adjust Mode"; the_lbldescription.textalignment =Nstextalignmentcenter; -_lbldescription.textcolor =[Uicolor Whitecolor]; -_lbldescription.numberoflines =0; - [Self.view addsubview:_lbldescription]; + -_lblmessage = [[UILabel alloc] Initwithframe:cgrectmake ( -,260, the, -)]; +_lblmessage.text =@"Click on the screen to toggle adjust mode; Automatically adjust the text size on the screen"; A_lblmessage.textcolor = [Uicolor colorwithred:0.335Green0.915Blue1.000Alpha1.000]; at_lblmessage.textalignment =Nstextalignmentcenter; -_lblmessage.backgroundcolor = [Uicolor colorwithred:0.852Green0.941Blue1.000Alpha1.000]; -_lblmessage.adjustsfontsizetofitwidth = NO;//default value is no -_lblmessage.baselineadjustment = Uibaselineadjustmentalignbaselines;//the Baselineadjustment property is valid only if the Adjustsfontsizetofitwidth property value is set to Yes, and the default value is Uibaselineadjustmentalignbaselines - [Self.view addsubview:_lblmessage]; - } in -- (void) didreceivememorywarning { to [Super didreceivememorywarning]; + //Dispose of any resources the can be recreated. - } the * #pragmaMark-private Methods $- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event {Panax Notoginseng Static inti =1; - Switch(i%4) { the Case 0: +_lblmessage.adjustsfontsizetofitwidth =NO; A_lbldescription.text =@"_lblmessage.adjustsfontsizetofitwidth = NO;"; the Break; + Case 1: -_lblmessage.adjustsfontsizetofitwidth =YES; $_lblmessage.baselineadjustment =Uibaselineadjustmentalignbaselines; $_lbldescription.text =@"_lblmessage.adjustsfontsizetofitwidth = YES; - _lblmessage.baselineadjustment = uibaselineadjustmentalignbaselines;"; - Break; the Case 2: -_lblmessage.adjustsfontsizetofitwidth =YES;Wuyi_lblmessage.baselineadjustment =uibaselineadjustmentaligncenters; the_lbldescription.text =@"_lblmessage.adjustsfontsizetofitwidth = YES; - _lblmessage.baselineadjustment = uibaselineadjustmentaligncenters;"; Wu Break; - Case 3: About_lblmessage.adjustsfontsizetofitwidth =YES; $_lblmessage.baselineadjustment =Uibaselineadjustmentnone; -_lbldescription.text =@"_lblmessage.adjustsfontsizetofitwidth = YES; - _lblmessage.baselineadjustment = Uibaselineadjustmentnone;"; - Break; A default: + Break; the } -i++; $ } the the @end
045 automatically adjust the text size in the screen