UI總結(一)

一.程序的組成結構
1.main.m 主要實現(xiàn)了程序的正常運行
2.APPDelegate 程序的執(zhí)行者,簽訂了UIApplicationDelegate
3.ViewController 視圖控制器 主要負責視圖管理 
4.Main.sb(視圖管理) LaunchScreen.sb(負責啟動頁) 可視化管理
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.中心點
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.行數(shù) numberOFLines 默認為 1 行
// 不確定行數(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 開始編輯時清除
    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;
重復次數(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; // 默認效果:從下而上
     UIModalTransitionStyleFlipHorizontal //左右旋轉翻頁
     UIModalTransitionStyleCrossDissolve // 漸變效果
     UIModalTransitionStylePartialCurl // 翻書效果
十.懶加載
    -(UIView *)subView{
    if (_subView  == nil) {
    _subView = [UIView new];
       }
     return _subView;
    }
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • 1.UILabel 1) label.frame //CGRectMake(x, y, width, he...
    青春flame閱讀 740評論 0 2
  • 代碼創(chuàng)建UIWindow對象 Xcode7之后使用代碼創(chuàng)建UIWindow對象: //創(chuàng)建UIWindow對象 s...
    云之君兮鵬閱讀 1,492評論 0 2
  • 一、UIView常見屬性 1.frame 位置和尺寸(以父控件的左上角為原點(0,0)) 2.center 中點(...
    脫下國際籃化身程序猿閱讀 359評論 0 0
  • *7月8日上午 N:Block :跟一個函數(shù)塊差不多,會對里面所有的內容的引用計數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,713評論 1 14
  • 今天突然發(fā)現(xiàn)個問題,我們好像生活在一個人和人之間總是彼此瞧不起的時代。愛看書的瞧不起不讀書的,覺得對方不讀書不看報...
    沫沫雜談閱讀 218評論 0 0

友情鏈接更多精彩內容