UI總結(jié)(一)

一.程序的組成結(jié)構(gòu)
1.main.m 主要實(shí)現(xiàn)了程序的正常運(yùn)行
2.APPDelegate 程序的執(zhí)行者,簽訂了UIApplicationDelegate
3.ViewController 視圖控制器 主要負(fù)責(zé)視圖管理 
4.Main.sb(視圖管理) LaunchScreen.sb(負(fù)責(zé)啟動頁) 可視化管理
5.Assets.xcassets 主要用來管理圖片素材(Xcode 7 以前叫 Images.xcassets)
6.Info.plist(工程配置文件)
二.window (繼承于NSObject)

// UIScreen 系統(tǒng)屏幕類

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible];
_window.rootViewController = [[ViewController alloc]init];
三.UIView
1.frame 和 bounds 的區(qū)別:

frame: 在父視圖上的相對位置
bounds:自身位置
2.中心點(diǎn)
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).方式三 擴(kuò)展類

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 默認(rèn)值 17)

label.font = [UIFont systemFontOfSize:40];
label.font = [UIFont boldSystemFontOfSize:20];// 字體加粗

2.對齊方式 NSTextAlignment
3.行數(shù) numberOFLines 默認(rèn)為 1 行
// 不確定行數(shù)時(shí),給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
  1. borderStyle 邊緣樣式

     UITextBorderStyleNone 無
     UITextBorderStyleLine 有邊緣線
     UITextBorderStyleBezel
     UITextBorderStyleRoundedRect 邊緣帶圓角
     textField.borderStyle = UITextBorderStyleLine;
     textField.borderStyle = UITextBorderStyleRoundedRect;(常用)
    

2.placeholder 占位符

  1. clearsOnBeginEditing 開始編輯時(shí)清除
    textField.clearsOnBeginEditing = YES;
    4.回收鍵盤(處理點(diǎn)擊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];

產(chǎn)生動畫的對象
imageView.animationImages = array;
時(shí)間間隔
imageView.animationDuration = 18 * 1 / 30;
重復(fù)次數(shù)
imageView.animationRepeatCount = 0;
開始動畫
[imageView startAnimating];

八.觸摸方法
    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
      }
九.模態(tài)

(1)寫法:
PresentViewController * present = [[PresentViewController alloc]init];
[self presentViewController:present animated:YES completion:nil];

(2).模態(tài)動畫效果

     present.modalTransitionStyle = UIModalTransitionStyleCrossrVertical; // 默認(rèn)效果:從下而上
     UIModalTransitionStyleFlipHorizontal //左右旋轉(zhuǎn)翻頁
     UIModalTransitionStyleCrossDissolve // 漸變效果
     UIModalTransitionStylePartialCurl // 翻書效果
十.懶加載
    -(UIView *)subView{
    if (_subView  == nil) {
    _subView = [UIView new];
       }
     return _subView;
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容