UI学习阶段性小结

#pragma mark  UI阶段性小结

//    UI(User Interface)用户界面

//    iOS App = 各种各样的UI控件 + 业务逻辑和算法

#pragma mark  一、UIView、UILabel、UIWindow

#pragma mark  1、frame是一个结构体,包含2个部分的内容:origin(x和y)和Size(width和height)

#pragma mark  2、bounds(边界)是view的重要属性

//    用于定义自己的边界,同frame一样是一个CGRect结构体变量。修改bounds.origin不会导致自身的位置发生变化,但会使添加在自身的子视图的位置发生变化。修改bounds.size会使自身大小发生变化。不会导致子视图的位置发生变化。

#pragma mark  3、UIView(视图) 添加和管理视图的方法

//    在指定的index处插入视图[superView insertSubview:grayView atIndex:1];

//    在指定的视图上面添加子视图[superview insertSubview:grayView aboveSubview:redView];

//    在指定的视图下面添加子视图[superview insertSubview:grayView belowSubview:redView];

//    把指定的子视图移动到最前面[superview bringSubviewToFront:redView];

//    把指定的子视图移动到最后面[superview sendSubviewToBack:redView];

//    交换两个指定索引位置的子视图[superview exchangeSubviewAtIndex:0 withSubviewAtIndex:2];

//    把receiver从父视图上移除[redView removeFromSuperview];

//    控制视图的显隐redView.hidden = YES;//隐藏redView redView.hidden = NO;//显⽰示redView

//    控制视图的不透明度(子视图也⼀一起 透明),取值范围0~1 redView.alpha = 0.8;

//    获取本视图的父视图UIView *superView = [redView superView];

//    获取本视图的所有子视图UIView *superView = [redView superView];

//    获取本视图的所有子视图NSArray *subviews = [redView subviews];

//    给视图添加标记,被加完标记的视 图可以使⽤用viewWithTag:⽅方法取出edView.tag = 100;UIView *view = [superview viewWithTag:100];

//    设置圆角度:view.layer.cornerRadius = NSInteger;(正方形设置圆角度为边长的一半,会变成圆形)

//    设置背景色:view.backgroundcolor

#pragma mark  4、UILabel(标签)显示文本的控件,UIView的子类

//    要显示的文本内容:label.text = @“⽤用户名”;

//    ⽂本内容的颜色:label.textColor = [UIColor redColor];

//    ⽂本的对齐方式(水平⽅向):label.textAlignment = NSTextAlignmentLeft;

//    文本字体及字体大小:label.font = [UIFont fontWithName:@“Helvetica-Bold” size:20];

//    行数:label.numberOfLines = 3;//设置为0时,会自动换行

//    断行模式label.lineBreakMode = NSLineBreakByWordWrapping;//以单词为单位换⾏

//    阴影颜色:label.shadowColor = [UIColor yellowColor];//阴影阴影

//    阴影⼤小:label.shadowOffset = CGSizeMake(2,1);//阴影向x正方向偏移2,向y正方向偏移1。

#pragma mark  5、UITextField(输入框)

//    UITextField(输入框):是控制文本输入和显示的控件

//    占位字符串(没有任何输入时,给出的提示字符串):textField.placeholder = @“请输⼊入⽤用户名”;

//    是否允许输⼊:textField.enabled =NO;//不允许输入,不弹出键盘textField.enabled =YES;//默认是YES。允许输入

//    是否开始输入的时候清空输入框内容:textField.clearsOnBeginEditing = YES;//清空textField.clearsOnBeginEditing = NO;//不清空

//    是否⽂字以圆点格式显示:textField.secureTextEntry = YES;//密码模式textField.secureTextEntry = NO;//普通模式

//    弹出键盘的类型(枚举值)textField.keyboardType = UIKeyboardTypeNumberPad; //数字键盘

//    键盘右下角return按钮类型(枚举值):textField.returnKeyType = UIReturnKeyNext;

//    自定义输入视图(默认是键盘)textField.inputView = myInputView;

//    输入视图上方的辅助视图(默认nil):textField.inputAccessoryView = myAccessoryView;

//    边框样式(枚举值)textField.borderStyle = UITextBorderStyleRoundedRect;

//    清除按钮模式(枚举值)textField.clearButtonMode = UITextFieldViewModeAlways; //总是显示清除按钮(一次性删除输入的内容)

//    输⼊框左视图textField.leftView = leftView;

//    左视图的显示模式左视图的显示模式textField.leftViewMode = UITextFieldViewModeAlways; //总是显示左视图

//    输入框右视图textField.rightView = rightView;

//    右视图的显示模式textField.rightViewMode = UITextFieldViewModeAlways;

//    设置背景图片 text.background = [UIImage imageNamed:@"dd.png"];

//    设置背景text.disabledBackground = [UIImage imageNamed:@"cc.png"];

//    是否纠错text.autocorrectionType = UITextAutocorrectionTypeNo;

//    再次编辑就清空  text.clearsOnBeginEditing = YES;

//    设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动 textFied.adjustsFontSizeToFitWidth = YES;

//    首字母是否大写  text.autocapitalizationType = UITextAutocapitalizationTypeNone;

//    代理实现textFieldShouldReturn:方法。

#pragma mark  6、UIButton(按钮)

//    UIButton(按钮):是响应用户点击的控件。UIButton:UIControl:UIView

//    为按钮添加事件,指定按钮点击之后,执行target的action方法 [loginButton addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpIn side];

//    移除按钮的点击事件[loginButton removeTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpIn side];

//    设置指定状态下的前景图片:setImage:forState:

//    设置指定状态下的标题背景颜色图片:setBackgroundimage:forState

//    定义按钮标题字体格式:[button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];

#pragma mark  7、自定义视图

//根据需求使用已学的基础控件组合创建继承与UIView的类,在类的初始化方法中添加子视图,在类的.h文件中提供一些借口(方法),便于外界操作子视图

#pragma mark  8、视图控制器、MVC设计模式

//    UIViewController:视图控制器

//    功能:控制视图⼤大⼩小变换、布局视图、响应事件。检测以及处理内存警告。检测以及处理屏幕旋转。检测视图的切换。

//    MVC是一个框架级的设计模式,M是Model,主要⽤于建立数据模型(即数据的结构);V是View,我们能看到的所有控件都是view,view主要的功能是展示数据;C是控制器,主要是控制M和V的通信。

#pragma mark  9、检测屏幕旋转//////http://www.cnblogs.com/seesea125/archive/2013/06/02/3114199.html

//     如果是在rootViewController中添加了方向控制,则他的子视图都默认继承rootViewController的方向控制。

//     1、设置设备支持旋转的⽅方向

    /*-(NSUInteger)supportedInterfaceOrientations

    {

        NSLog(@"支持旋转");

        return UIInterfaceOrientationMaskAll;

    }*/

//       2、暂停⾳音乐、关闭视图交互等

/*    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

    {

        self.rootView.userInteractionEnabled = NO;

        NSLog(@"------将要旋转");

    }*/

//      3、添加⾃自定义动画

    /*-(void)willAnimateRotationToInterfaceOrientation:duration:*/

//      4、完成旋转(打开交互)

    /*-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

    {

        self.rootView.userInteractionEnabled = YES;

        NSLog(@"-------完成旋转");

    }*/

//      5、[UIApplication shareApplication].statusBarOrientation提供设备 当前⽅方向。

#pragma mark   10、处理内存警告/////http://justsee.iteye.com/blog/1820588

    /*- (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        if ([self isViewLoaded] ==YES && self.view.window == nil) {

            self.view = nil;

            NSLog(@"内存警告!");

        }

        // Dispose of any resources that can be recreated.

    }*/

#pragma mark  11、容器试图控制器

/*     页面即将展开的时候,揭开画布

    -(void)viewWillAppear:(BOOL)animated

    {

        

    }

//    #pragma mark 页面完全展开以后

    //完成揭画布

    -(void)viewDidAppear:(BOOL)animated

    {

        

    }

//     页面即将消失

    -(void)viewWillDisappear:(BOOL)animated

    {

        

        

    }

//     页面已经消失的时候

    -(void)viewDidDisappear:(BOOL)animated

    {

        

    }*/

#pragma mark   12、UIEvent:事件:触摸事件、晃动事件、远程控制事件

//    UIEvent:事件。由硬件捕捉到的一个表示用户操作设备的对象

//    为实现多点触摸,首先设置view的属性multipleTouchEnabled = YES(注意了。。。默认值是NO);

//    实现触摸相关的方法:touches..began、touches..moved、touches...ended、 touches..canceled。均无返回值。

//    UITouch初始化:UITouch *touch = [touches anyObject];

#pragma mark   13、响应者链/////http://my.oschina.net/hmj/blog/108002

//    响应者链:由多个响应者对象组成的链

//    UIResponder。响应者类。

//    硬件检测到触摸操作,会将信息交给UIApplication,开始检测。检测顺序:UIApplication -> window -> viewController -> view -> 检测所有⼦子 视图,最终确认触碰位置,完成响应者链的查询过程,事件处理的顺序与触摸检测查询相反。

//    iOS使用hit-testing寻找触摸的view。 Hit-Testing通过检查触摸点是否在关联的view边界内,如果在,则递归地(recursively)检查该view的所有子view。在层级上处于lowest(我理解就是离用户最近的view)且边界范围包含触摸点的view成为hit-test view。确定hit-test view后,它传递触摸事件给该view。

//    响应者链可以被打断。无法完成检测查询过程。视图类的属性 : userInteractionEnabled。关闭后能阻断查询过程。默认关闭响应交互的类有:UILabel、UIImageView

#pragma mark    14、设计模式:target/action设计模式、delegate模式(代理设计模式)

//    耦合是衡量模块与模块之间关联程度的指标,“高内聚。低耦合”是面向对象编程的核心思想。

//    target/action设计模式模式的劣势:每个视图的点击事件都不一样,如何处理?无法预知视图点击之后要实现的效果,因此在类内写好点击事件不科学也不全面

//    delegate模式:当不明确一个类的某些功能,又不确定谁来实现这些功能的时候,可以使用委托模式,目的就是为了降低类之间的耦合性。

#pragma mark    15、UIImageView

//    创建动态图

/*

        NSMutableArray *array2 = [NSMutableArray array];

        for (int i = 11; i <= 21; i++) {

            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.tiff",i]];

            [array2 addObject:image];

        }

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 320, 180)];

        imageView.animationImages =array2;

        imageView.animationDuration = 1.5f;

        [imageView startAnimating];

        [self addSubview:imageView];

        [imageView release];*/

#pragma mark    16、手势识别器:

//    手势识别器是对触摸事件做了封装,我们无需去判断某个手势是否触发,手势识别器本身起到了识别的作用,我们把重心放在识别手势之后要做什么操作上面。根据需要使用特定手势识别器创建对象,使用initwithTarget:action:方法。

//    1.  轻拍手势

    /*UITapGestureRecognizer *tapGP = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGRAction)];

    tapGP.numberOfTapsRequired = 2;

    [self.rootView.aView addGestureRecognizer:tapGP];*/

//    2. 长按手势

//    UILongPressGestureRecognizer

//    3.旋转手势

//    UIRotationGestureRecognizer

//    4.捏合手势

//    UIPinchGestureRecognizer

//    5.平移手势

//    UIPanGestureRecognizer

//    6.轻扫手势,,,需要设置旋转的角度

//    UISwipeGestureRecognizer

//    7.边缘轻扫手势 ,是iOS7中新增的手势,默认是从屏幕右向左轻扫,如果要改轻扫的方向,可以通过修改参数edges实现

//    UIScreenEdgePanGestureRecognizer

#pragma mark    17、view的transform属性(view的缩放、旋转、平移).....不太懂,查资料

//    transform是view的一个重要属性,它在矩阵层面上改变view 的显示状态,能实现view的缩放、旋转、平移等等功能。

#pragma  mark    18、UISegmentedControl(分段控件,按钮栏)http://www.cnblogs.com/top5/archive/2012/05/17/2506618.html

//    自己的初始化方法:UISegmentedControl *segmentedControl = [[UISegmentedControlalloc]initWithItems:segmentedArray];//因为title是一系列的字符串,因此放在数组里

//    设置默认选择项索引:segmentedControl.selectedSegmentIndex = 2;

//    设置样式:segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;

//    设置指定索引的图片:[segmentedControl setImage:[UIImage imageNamed:@"btn_jyy.png"] forSegmentAtIndex:3];  //设置文字同理

//    在指定索引插入一个选项并设置图片:[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"mei.png"] atIndex:2 animated:NO];

//    设置指定索引选项的宽度:[segmentedControl setWidth:70.0 forSegmentAtIndex:2];

//    添加委托方法:[mySegmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];//实现方法中可以使用if语句或者swith语句判断

//    设置在点击后是否恢复原样:segmentedControl.momentary = YES;

//    例:在导航栏中添加UISegmentedControl

    //自定义UISegmentedcontrol

/*

    UISegmentedControl *segmentedControl=[[UISegmentedControl alloc] initWithFrame:CGRectMake(80.0f, 8.0f, 200.0f, 30.0f) ];

    [segmentedControl insertSegmentWithTitle:@"Food to eat" atIndex:0 animated:YES];

    [segmentedControl insertSegmentWithTitle:@"Food to avoid" atIndex:1 animated:YES];

    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

    segmentedControl.momentary = YES;

    segmentedControl.multipleTouchEnabled=NO;

    [segmentedControl addTarget:self action:@selector(Selectbutton:) forControlEvents:UIControlEventValueChanged];

    UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];  //自定义UIBarButtonItem,封装定义好的UIsegmented。

    [segmentedControl release];

    self.navigationItem.rightBarButtonItem = segButton;  //添加到导航栏中

    [segButton release];*/

#pragma mark    19、UISlider(滑块控件):UIControl http://www.cnblogs.com/top5/archive/2012/05/17/2506621.html

//    slider.minimumValue = 0;//指定可变最小值

//    slider.maximumValue = 100;//指定可变最大值

//    slider.value = 50;//指定初始值

//    minimumTrackTinkColor //定义划过区域的颜色

//    [slider addTarget:self action:@selector(updateValue:) forControlEvents:UIControlEventValueChanged];//设置响应事件

//    设置UISlider的样式见链接

#pragma mark     20、模态控制

//    通过presentViewController指定当前的控制器,实现页面的跳转

//    YQSecondController *controller2 = [[YQSecondController alloc]init];

//    [self presentViewController:controller2 animated:NO completion:nil];

#pragma mark     21、UISwitch(开关)

#pragma mark     22、UIStepper

#pragma mark     23、UIScrollView(可以滚动的View)

//    UIScrollView是所有滚动视图的基类。

//    UIScrollview主要专长于两个方面:1.滚动:contentSize⼤于frame.size的时候,能够滚动。缩放:⾃带缩放,可以指定缩放倍数。

//    contentSize //定义内容区域⼤小,决定是否能够滑动

//    contentOffset //视图左上⾓角距离坐标原点的偏移量

//    pagingEnabled //是否整屏翻动

//    bounces //边界是否回弹

//    scrollEnabled //是否能够滚动

//    minimumZoomScale // 缩⼩小的最⼩小⽐比例

//    maximumZoomScale //放⼤大的最⼤大⽐比例

//    zoomScale//设置变化⽐比例

//    zooming//判断缩放的时候是否会反弹

//    bouncesZoom//控制缩放的时候是否会反弹

//    要实现缩放,还需要实现delegate,指定缩放的视图是谁。

//    UIScrollView滚动代理方法

//    滚动就会触发:- (void)scrollViewDidScroll:(UIScrollView *)scrollView

//    开始拖拽时触发:- (void)scrollViewWillBeginDragging:

//    (UIScrollView *)scrollView

//    结束拖拽时触发:- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView  willDecelerate:(BOOL)decelerate

//    开始减速时触发:- (void)scrollViewWillBeginDecelerating:

//    (UIScrollView *)scrollView

//    结束减速时触发(停⽌止时)- (void)scrollViewDidEndDecelerating:

//    (UIScrollView *)scrollView

//    完成放大缩小触发:- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale

//    指定某个UIScrollView的子视图可以被放大缩小:- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

#pragma mark    24、UIScrollView设置首次登陆时浏览图片(引导页)

//    添加在AppDelegate.m文件中

    /*

    -(void)addFollowView

    {

        if ([[NSUserDefaults standardUserDefaults]boolForKey:@"flag"] == NO) {

            [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"flag"];

            UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];

            scrollView.contentSize = CGSizeMake(320*7, [UIScreen mainScreen].bounds.size.height);

            scrollView.pagingEnabled = YES;

            [self.window addSubview:scrollView];

            for (int i = 1; i < 8; i++) {

                UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]]];

                imageView.frame = CGRectMake(320*(i-1), 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

                [scrollView addSubview:imageView];

                if (i == 7) {

                    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

                    button.backgroundColor = [UIColor blueColor];

                    button.frame = CGRectMake(100, 400, 120, 45);

                    [button setTitle:@"点击我进入应用" forState:UIControlStateNormal];

                    [button addTarget:self action:@selector(buttonDidClicked:) forControlEvents:UIControlEventTouchUpInside];

                    imageView.userInteractionEnabled = YES;

                    [imageView addSubview:button];

                    

                }

                [imageView release];

            }

            [scrollView release];

        }else{

            YQRootController *rootVc = [[YQRootController alloc]init];

            self.window.rootViewController = rootVc;

            [rootVc release];

            

        }

        

    }

    -(void)buttonDidClicked:(UIButton *)sender

    {

        YQRootController *rootVc = [[YQRootController alloc]init];

        self.window.rootViewController = rootVc;

        [rootVc release];

    }*/

#pragma mark    25、UIPageControl(指示当前的页码)

//    所以可以像button⼀一样添加事件,只不过事件触发使⽤用的不是 UIControlEventsTouchUpInside⽽是 UIControlEventsValueChanged。

//    通常在Scrollview滚动的时候修改pageControl的currentPage

#pragma mark     26、UINavigationController(导航控制器)

//    导航栏控制器可以认为是管理控制器的控制器,主要管理有层级关系的控制器。

//    UINavigationController继承与UIViewController,以栈的方式管理所控制的视图控制器,至少要有一个被管理的视图控制器,这个控制器我们称作:导航控制器的根视图控制器。任何继承自UIViewController的类(多态)口可以作为根控制器。

//    pushViewController:animated //进入下一个视图控制器

//    popViewController:Animated: //返回上一个视图控制器

//    popToViewController:animated //返回到指定的视图控制器

//    popToRootViewController:Animated //返回到根视图控制器

#pragma mark    27、navigationBar(导航条)

//    navigationBar在iOS7之后默认是透明的,iOS之前默认是不透明的。

//    navigationBar在透明的情况下,与contentView会重合一部分区域。

//    navigationBar在不透明的情况下,contentView跟在navigationBar的下面。

//    navigationBar竖屏下默认高度是44,横屏默认高度是32.

//    设置导航条的方法:barTintColor //setBackgroundImage:forBarMetrics:

//    每个视图控制器都有一个navigationItem属性。navigationItem中设置的左按钮(leftBarButtonItem)、右按钮(rightBarButtonItem)、标题(titleView)等,会随着控制器的显示也显示到navigationItem上。

//    UIBarButtonItem属于MVC的M。定义了UINavigationItem上按钮的触发事件,外观等。

//    初始化方法包括:-initWithTitle:style:target:action://///-initWithBarButtonSystemItem:target:action://////-initWithImage:style:target:action:等

#pragma mark    28、界面间传值(属性传值、代理传值)

//    查看Lesson8_class

#pragma mark     29、UITableView:UIScrollView 参考:http://www.cnblogs.com/kenshincui/p/3931948.html(基础应用),,cell的重布局:直接向cell的contentView上面添加subView、、、:从UITableViewCell派生一个类可参考:http://www.cnblogs.com/smileEvday/archive/2012/06/28/tableView.html

原文地址:https://www.cnblogs.com/jyq-blog/p/4525894.html