UI总结(一)

一.程序的组成结构
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
  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;
重复次数
imageView.animationRepeatCount = 0;
开始动画
[imageView startAnimating];

八.触摸方法
    -(void)touchesBegan:(NSSet *)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;
    }

你可能感兴趣的:(UI总结(一))