一.程序的組成結構
1.main.m 主要實現了程序的正常運行
2.APPDelegate 程序的執行者,簽訂了UIApplicationDelegate
3.ViewController 視圖控制器 主要負責視圖管理
4.Main.sb(視圖管理) LaunchScreen.sb(負責啟動頁) 可視化管理
5.Assets.xcassets 主要用來管理圖片素材(Xcode 7 以前叫 Images.xcassets)
6.Info.plist(工程配置文件)
二.window (繼承于NSObject)
// UIScreen 系統屏幕類
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible];
_window.rootViewController = [[ViewController alloc]init];
三.UIView
1.frame 和 bounds 的區別:
frame: 在父視圖上的相對位置
bounds:自身位置
2.中心點
view1.center = CGPointMake(10,10);
3.改變大小
(1).方式一:
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, 100, view.frame.size.height);
(2).方式二:
CGRect rect = view.frame;
rect.size.width = 100;
view.frame = rect;
(3).方式三 擴展類
view.lyr_width = 100;
UIView+Frame.h
@property(nonatomic,assign)CGFloat lyr_x;
@property(nonatomic,assign)CGFloat lyr_y;
@property(nonatomic,assign)CGFloat lyr_width;
@property(nonatomic,assign)CGFloat lyr_height;
UIView+Frame.m
-(void)setLyr_x:(CGFloat)lyr_x{
CGRect rect = self.frame;
rect.origin.x =lyr_x;
self.frame = rect;
}
-(CGFloat)lyr_x{
return self.frame.origin.x;
}
4.tag -> viewWithTag
UIView * view1 =[_window viewWithTag:1000];
5.添加視圖
(1).addSubView:
(2).insertSubView:atIndex:
(3).insertSubView:aboveSubView:
(4).insertSubView:belowSubView:
四.Label
1.改變字體大小:( font 默認值 17)
label.font = [UIFont systemFontOfSize:40];
label.font = [UIFont boldSystemFontOfSize:20];// 字體加粗
2.對齊方式 NSTextAlignment
3.行數 numberOFLines 默認為 1 行
// 不確定行數時,給0
4.換行模式,省略模式
// 按單詞換行
label.lineBreakMode = NSLineBreakByWordWrapping;
//......abc
label.lineBreakMode = NSLineBreakByTruncatingHead;
//abc.....
label.lineBreakMode = NSLineBreakByTruncatingTail;
// abc...chd
label.lineBreakMode = NSLineBreakByTruncatingMiddle;
5.shadow陰影
label.shadowOffset = CGSizeMake(2, 0);
label.shadowColor = [UIColor whiteColor];
五.UITextField
-
borderStyle 邊緣樣式
UITextBorderStyleNone 無 UITextBorderStyleLine 有邊緣線 UITextBorderStyleBezel UITextBorderStyleRoundedRect 邊緣帶圓角 textField.borderStyle = UITextBorderStyleLine; textField.borderStyle = UITextBorderStyleRoundedRect;(常用)
2.placeholder 占位符
-
clearsOnBeginEditing 開始編輯時清除
textField.clearsOnBeginEditing = YES;
4.回收鍵盤(處理點擊return)-(BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField endEditing:YES];// 回收鍵盤 return YES; }
六.播放器邏輯
播放:
-(void)playSong:(UIButton *)playButton{
NSLog(@"播放");
[playButton removeTarget:self action:@selector(playSong:) forControlEvents:(UIControlEventTouchUpInside)];
[playButton addTarget:self action:@selector(pasueSong:) forControlEvents:(UIControlEventTouchUpInside)];
[playButton setTitle:@"暫停" forState:(UIControlStateNormal)];
}
暫停:
-(void)pasueSong:(UIButton *)pasueSong{
NSLog(@"暫停");
[pasueSong removeTarget:self action:@selector(pasueSong:) forControlEvents:(UIControlEventTouchUpInside)];
[pasueSong addTarget:self action:@selector(playSong:) forControlEvents:(UIControlEventTouchUpInside)];
[pasueSong setTitle:@"播放" forState:(UIControlStateNormal)];
}
七.UIImageView動畫
UIImageView * imageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
NSMutableArray * array = [NSMutableArray array];
for (int i = 1; i < 19; i ++) {
NSString * flowerName = [NSString stringWithFormat:@"flower%d.tiff",i];
UIImage * flowerImage = [UIImage imageNamed:flowerName];
[array addObject:flowerImage];
}
[_window addSubview:imageView];
產生動畫的對象
imageView.animationImages = array;
時間間隔
imageView.animationDuration = 18 * 1 / 30;
重復次數
imageView.animationRepeatCount = 0;
開始動畫
[imageView startAnimating];
八.觸摸方法
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
}
九.模態
(1)寫法:
PresentViewController * present = [[PresentViewController alloc]init];
[self presentViewController:present animated:YES completion:nil];
(2).模態動畫效果
present.modalTransitionStyle = UIModalTransitionStyleCrossrVertical; // 默認效果:從下而上
UIModalTransitionStyleFlipHorizontal //左右旋轉翻頁
UIModalTransitionStyleCrossDissolve // 漸變效果
UIModalTransitionStylePartialCurl // 翻書效果
十.懶加載
-(UIView *)subView{
if (_subView == nil) {
_subView = [UIView new];
}
return _subView;
}