1, the use of the timer
[Nstimer scheduledtimerwithtimeinterval:0.01 target:self selector: @selector (flyaction) Userinfo:nil Repeats:yes];
2, the use of random numbers
Arc4random ()
3. UIWindow part code (XIB)
UIScreen
CGRect rect = [UIScreen mainscreen].bounds;
Create UIWindow
Self.window = [[UIWindow alloc] initwithframe:rect];
Set Background color
Self.window.backgroundColor = [Uicolor blackcolor];
Set the Keywindow and make it visible
[Self.window makekeyandvisible];
Adding a host controller
Viewcontroller * VC = [[Viewcontroller alloc] init];
Self.window.rootViewController = VC;
4, UIView part of the code
Place v at the front
[Self.view Bringsubviewtofront:v];
Place v at the end
[Self.view Sendsubviewtoback:v];
Delete a child view from a parent view
[v Removefromsuperview];
5. Calculate the height of the label (core code)
CGRect rect = [string Boundingrectwithsize:cgsizemake (width, maxfloat) options:nsstringdrawinguseslinefragmentorigin Attributes:dict Context:nil];
6. Adaptive (Core code)
(1) SizeToFit
UILabel * label = [[UILabel alloc] Initwithframe:cgrectmake (0, 20, 17, 0)];
Label.text = string;
Label.numberoflines = 0;
Be sure to set the width using SizeToFit
[Label SizeToFit];
(2) Sizethatfits:
UILabel * label = [[UILabel alloc] init];
Label.text = string;
Label.numberoflines = 0;
Label.backgroundcolor = [Uicolor Greencolor];
Cgsize size = [Label Sizethatfits:cgsizemake (SELF.VIEW.FRAME.SIZE.WIDTH-40, maxfloat)];
Label.frame = CGRectMake (Size.width, size.height);
[Self.view Addsubview:label];
7, UIImage part of the code
(1) Location under this catalogue
Resource: File name
OfType: filename suffix
Directories under the Indirectory:bundle
NSString * path =[[nsbundle mainbundle] pathforresource:@ "test" oftype:@ "plist" indirectory:@ "image"];
(2) Easy stretching
uiimage* image = [UIImage imagenamed:@ "BackgroundImage"];//has cache
uiimageview* ImageView =[[uiimageview Alloc]initwithimage:image];
Uiedgeinsets inset = Uiedgeinsetsmake (6, 6, 6, 6);
image = [Image Resizableimagewithcapinsets:inset Resizingmode:uiimageresizingmodestretch];
Imageview.image = image;
Imageview.frame = CGRectMake (self.view.frame.size.width-40, 30);
[Self.view Addsubview:imageview];
(3) Round cut
ImageView.layer.cornerRadius = 10
Hide something outside the circle
ImageView.layer.masksToBounds = YES;,//Hide
Imageview.clipstobounds = yes;//Cut off
Set Edge width
ImageView.layer.borderWidth = 4;
Set Edge Color
ImageView.layer.borderColor = [Uicolor blackcolor]. Cgcolor;
Set Shadow Color
ImageView.layer.shadowColor = [Uicolor Greencolor]. Cgcolor;
Set Shadow Size
ImageView.layer.shadowOffset = Cgsizemake (2, 2);
Set opacity
ImageView.layer.shadowOpacity = 0.3;
(4) Animation
Nsmutablearray * array = [Nsmutablearray array];
for (int i = 1; i < 6; i++) {
NSString * string = [NSString stringwithformat:@ "hehua0%d", I];
UIImage * image = [UIImage imagenamed:string];
[Array addobject:image];
}
ImageView = [[Uiimageview alloc] initwithframe:cgrectmake (100, 100, 200, 200)];
Set up animated pictures
Imageview.animationimages = array;
Animation time
Imageview.animationduration = 1;
Animation playback repetition, value 0 o'clock, infinite loop
Imageview.animationrepeatcount = 0;
Start animation
[ImageView startanimating];
[Self.view Addsubview:imageview];
8, UIButton part of the code
(1) button implementation on the graph (core code)
-(Instancetype) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self) {
Self.imageView.contentMode = Uiviewcontentmodebottom;
Self.titleLabel.textAlignment = Nstextalignmentcenter;
Self.titleLabel.font = [Uifont systemfontofsize:20];
}
return self;
}
-(CGRect) Imagerectforcontentrect: (CGRect) Contentrect {
CGFloat PONITX = 0;
CGFloat ponity = 0;
CGFloat width = contentRect.size.width;
CGFloat height = contentRect.size.height * Kscale;
Return CGRectMake (PONITX, ponity, width, height);
}
-(CGRect) Titlerectforcontentrect: (CGRect) Contentrect {
CGFloat PONITX = 0;
CGFloat ponity = contentRect.size.height * Kscale;
CGFloat width = contentRect.size.width;
CGFloat height = contentRect.size.height * (1-kscale);
Return CGRectMake (PONITX, ponity, width, height);
}
9, Uitextfield part of the code
(1) First Response (keyboard pop-in Popup)
Make a first response
[Self.view Addsubview:textfield];
-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *) Event {
Cancel First Response
[Self.textfield Resignfirstresponder];
End Edit
[Self.textfield Endediting:yes];
}
iOS Learning Day6