美文网首页iOS Developer
ios UI控件的简单整理(4)

ios UI控件的简单整理(4)

作者: 蜗蜗牛在奔跑 | 来源:发表于2017-04-21 09:23 被阅读20次

    #pragma mark - UIImageView// 图片转为NSDataUIImagePNGRepresentation(_ivView.image)// 图片转为点阵图(防止渲染)[_ivView.imageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];// 显示图片大小为imageView大小_starsView.contentMode= UIViewContentModeLeft;

    _starsView.clipsToBounds=YES;// 设置图像填充模式,等比例显示(CTRL+6)iv.contentMode= UIViewContentModeScaleAspectFit;// 从iPhone4开始,设备的屏幕都是retina屏(2倍,一个坐标位横向纵向显示2个像素点,高清屏,视网膜屏),(6p是3倍的)// retina屏幕会优先找a@2x.png,找不到就找a.pngiv.image= [UIImageimageNamed:@"a"];// 图片对象(自带的大小是坐标体系的大小,如果用的是@2x图片,像素大小的宽高除以2就是坐标体系的大小UIImage*image = [UIImageimageNamed:@"c"];// 用图片直接创建图片视图,x,y默认是0,宽高默认是图片的大小UIImageView*secondIv = [[UIImageViewalloc] initWithImage:image];/** 图片轮播 **/// 设置图片视图轮播图片的数组,单次动画时间,循环次数(默认无线循环,0次也是无线循环),开始动画iv.animationImages= tempArr;

    iv.animationDuration= tempArr.count/10.0f;

    iv.animationRepeatCount=0;

    [iv startAnimating];/*

    //开始动画

    - (void)startAnimating;

    //手动结束动画

    - (void)stopAnimating;

    //判断动画状态

    - (BOOL)isAnimating;

    //图片

    @property(nonatomic,retain) UIImage *image;

    //动画的图片数组

    @property(nonatomic,copy) NSArray *animationImages;

    //动画时间(也就是一次完整的动画需要的时间)

    @property(nonatomic) NSTimeInterval animationDuration;

    //动画循环次数,循环完以后会自动停止

    @property(nonatomic) NSInteger animationRepeatCount;

    */#pragma mark - UITextFiled// 占位提示符tf.placeholder= @"请输入QQ号";// 边框风格tf.borderStyle= UITextBorderStyleLine;// 背景图片(和边框风格冲突)// 如果风格是圆角,那么背景图片失效// 如果边框风格不是圆角,那么边框风格失效tf.background= [UIImageimageNamed:@"tf_bg"];// 当字符串的长度超过tf的长度,可以自动缩小字体tf.adjustsFontSizeToFitWidth=YES;// 自动缩小的最小值tf.minimumFontSize=30;// 水平方向的对齐方式(同label)tf.textAlignment= NSTextAlignmentRight;// 垂直方向对齐方式(同button)tf.contentVerticalAlignment= UIControlContentVerticalAlignmentBottom;// 当字符串的长度超过tf的长度,可以自动缩小字体tf.adjustsFontSizeToFitWidth=YES;// 自动缩小的最小值tf.minimumFontSize=30;// 水平方向的对齐方式(同label)tf.textAlignment= NSTextAlignmentRight;// 垂直方向对齐方式(同button)tf.contentVerticalAlignment= UIControlContentVerticalAlignmentBottom;// 当弹出键盘的时候,清空tf的文字tf.clearsOnBeginEditing=YES;// 设置清空按钮出现的方式tf.clearButtonMode= UITextFieldViewModeWhileEditing;// 安全输入(暗文输入,专门输入密码使用)tf.secureTextEntry=YES;// 键盘类型tf.keyboardType= UIKeyboardTypeDefault;// 回车键的外观(和功能没有任何关系)tf.returnKeyType= UIReturnKeyNext;// 设置tf的左边的附属view的出现模式(实际工作中一般都是图片imageview)// 一个view只能成为一个地方的附属viewtf.leftView= view;

    tf.leftViewMode= UITextFieldViewModeAlways;// 键盘view和附属viewtf.inputView= view;

    tf.inputAccessoryView= view;// 收起这个页面的键盘[self.viewendEditing:YES];// 放弃第一响应[self.viewresignFirstResponder]#pragma mark - UIViewController// 第一种跳转- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    {// 通过连线的标识符来执行某个跳转// segue过渡的意思[selfperformSegueWithIdentifier:@"PushToCyan"sender:nil];

    }// 第二种跳转// 通过storyboard跳转页面时都会走这个方法// 第一个参数就是跳转的那根连线,第二个参数暂时理解成触发跳转的对象(storyboard里已经画出的view)- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

    {// 通过连线找到跳转到的页面UIViewController*nextVC = [segue destinationViewController];

    nextVC.view.backgroundColor= [UIColoryellowColor];// self.tableView就是表格页面自动带的tableview// 在一个tableView里通过cell找到所处的位置MovieCell *cell = (id)sender;NSIndexPath*path = [self.tableViewindexPathForCell:cell];

    }// 第三种跳转// 找到自带的Main.storyboardUIStoryboard *sd = [UIStoryboard storyboardWithName:@"Main"bundle:nil];UIViewController*vc = [sd instantiateViewControllerWithIdentifier:@"Cyan"];

    [self.navigationControllerpushViewController:vc animated:YES];// 声明周期3-->-[ThirdViewController initWithNibName:bundle:]3-->-[ThirdViewController viewDidLoad]3-->-[ThirdViewController viewWillAppear:]3-->-[ThirdViewController viewDidAppear:]

    -[FourthViewController initWithNibName:bundle:]

    -[FourthViewController viewDidLoad]3-->-[ThirdViewController viewWillDisappear:]

    -[FourthViewController viewWillAppear:]3-->-[ThirdViewController viewDidDisappear:]

    -[FourthViewController viewDidAppear:]

    -[FourthViewController viewWillDisappear:]3-->-[ThirdViewController dealloc]

    -[FourthViewController viewDidDisappear:]

    -[FourthViewController dealloc]//弹出一个新的viewController- (void)presentViewController:(UIViewController*)viewControllerToPresent animated: (BOOL)flag completion:(void(^)(void))completion;//销毁当前viewcontroller- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void(^)(void))completion;#pragma mark - UINavigationController// 设置导航栏(导航栏是属于导航控制器的)// 导航栏分为两部分(工具条高 20,以下高44)// 针对导航栏的设置,全影响到整个导航控制器// 设置导航栏的隐藏状态self.navigationController.navigationBarHidden=NO;// 通过vc找到nc,通过nc找到导航栏,设置背景色self.navigationController.navigationBar.barTintColor= [UIColormagentaColor];// 设置导航栏内容的渲染色(自带的返回按钮)self.navigationController.navigationBar.tintColor= [UIColorgreenColor];// 半透明状态,如果写成YES,(0,0)坐标点在导航栏的左上角// 如果写成NO,(0,0)坐标点在导航栏的左下角self.navigationController.navigationBar.translucent=NO;// 设置背景图(平铺模式:即如果图片过小,重复显示)(会引起坐标原点的改变)// 以iPhone为例,如果图片size是320*44,那么就会展示成ios7以前的效果(系统状态栏和导航栏完全分离)[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"aaa"] forBarMetrics:UIBarMetricsDefault];// 这个方法可以获取当前导航栏[UINavigationBarappearance];// 设置导航栏title的文字属性self.navigationController.navigationBar.titleTextAttributes= [NSDictionarydictionaryWithObjectsAndKeys:[UIFontsystemFontOfSize:10], NSFontAttributeName, [UIColorpurpleColor], NSForegroundColorAttributeName,nil];// 展示在当前页导航栏正中间的view,设置了这个view,title就不显示了self.navigationItem.titleView= label;/*

    4种创建专用按钮

    a,使用字符串创建

    b,使用图片(默认会被渲染,需要注意图片的大小写)

    c,使用系统自带的风格

    d,自定义(一般都用UIButton)

    */UIBarButtonSystemItemFlexibleSpace,是自带的一种空的item,可以当作占位符用

    [[UIImageimageNamed:@"gerenzhuye"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal],去除图片的渲染// 将专有按钮放到当前导航栏的左边UIBarButtonItem*aItem = [[UIBarButtonItemalloc] initWithTitle:@"aItem"style:UIBarButtonItemStylePlain target:selfaction:@selector(itemClick)];

    [aItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIFontsystemFontOfSize:10], NSFontAttributeName,nil] forState:UIControlStateNormal];self.navigationItem.leftBarButtonItem= aItem;// 使用图片创建专用按钮(只取轮廓,不取颜色,系统会把不透明的地方渲染了)(默认渲染色为蓝色)UIBarButtonItem*bItem = [[UIBarButtonItemalloc] initWithImage:[UIImageimageNamed:@"haoyou"] style:UIBarButtonItemStyleDone target:selfaction:@selector(itemClick)];// 使用系统自带的风格UIBarButtonItem*cItem  = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:selfaction:@selector(itemClick)];// 使用view创建专有按钮(一般用btn,只有用btn才能添加监听事件)UIBarButtonItem*dItem = [[UIBarButtonItemalloc] initWithCustomView:btn];// 系统自定义按钮self.navigationItem.leftBarButtonItem=self.editButtonItem;#pragma mark - UITabBarController/*

    使用tabBarController的基本思路

    1,创建所有展示的页面

    2,如果需要将页面放到导航里

    3,设置每个页面或者导航显示到tabBar上的专用按钮

    4,将页面或者导航放到数组里,并且和标签栏控制器关联

    */// 初始化分栏控制器(标签栏控制器)UITabBarController*tbc = [[UITabBarControlleralloc] init];// 设置需要控制的页面(可以是普通页面,也可以是导航控制器)tbc.viewControllers= [NSArrayarrayWithObjects:av, bnc, cv, dv, ev, fv, gv,nil];// 推出新页面的时候,隐藏底层标签栏,返回的时候会自动出现gv.hidesBottomBarWhenPushed=YES;/* 创建专用按钮的3中方式 */// 创建一个标签栏的专用按钮(系统自带样式)UITabBarItem *homeItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];

    homeNC.tabBarItem= homeItem;// 使用一个字符串和一个图片创建专用按钮(默认渲染图片)// UITabItem使用的图片最合适的大小是30*30UITabBarItem *loveItem = [[UITabBarItem alloc] initWithTitle:@"love"image:[UIImageimageNamed:@"tab_0"] tag:0];// 使用一个字符串和2张图片创建(默认会渲染)UITabBarItem *nearlyItem = [[UITabBarItem alloc] initWithTitle:@"nearly"image:[UIImageimageNamed:@"tab2_1"] selectedImage:[UIImageimageNamed:@"tab2_2"]];// 设置渲染色UITabBarController.tabBar.tintColor= [UIColorredColor];// 设置背景颜色UITabBarController.tabBar.barTintColor= [UIColorcyanColor];// 背景图片UITabBarController.tabBar.backgroundImage= [UIImageimageNamed:@"tabbg"];// 显示字体属性,字体属性单独设置[homeItem setTitleTextAttributes:[NSDictionarydictionaryWithObject:[UIFontsystemFontOfSize:10] forKey:NSFontAttributeName] forState:UIControlStateNormal];// 让分栏控制器里对应的页面,展示出来self.selectedIndex= sender.tag-100;#pragma mark - UIScrollView// 设置滚动试图内可以展示的最大的sizesv.contentSize= CGSizeMake(480,480);// 设置偏移量(偏移就是位移,现在展示的子视图和默认子视图相比移动的距离)sv.contentOffset= CGPointMake(20,20);// 水平和垂直方向的进度条// 在有些版本里,垂直隐藏,水平也就不显示了sv.showsHorizontalScrollIndicator=NO;

    sv.showsVerticalScrollIndicator=NO;// 弹簧效果sv.bounces=NO;// 代理方法中的bool值// decelerate代表松手以后sv是否会继续滑行(1代表会)// 如果页面实在导航里,而且第一个子视图是sv,那么系统会让这个sv有一个自动下沉的效果self.automaticallyAdjustsScrollViewInsets=NO;// sv中只能有一个子视图可以被缩放// 如果sv中有多个子视图,缩放的时候会对整个sv产生不可预料的后果// 最大、最小缩放倍数sv.minimumZoomScale=0.5;

    sv.maximumZoomScale=2;// 放大缩小的代理- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView

    {return[scrollView viewWithTag:1];

    }#pragma mark - UIPageControl// 翻页控制器UIPageControl *pc = [[UIPageControl alloc] initWithFrame:CGRectMake(100,450,0,0)];// 根据页数自动分配大小[pc sizeForNumberOfPages:5];// 设置页数pc.numberOfPages=5;// 小点点的颜色pc.currentPageIndicatorTintColor= [UIColorredColor];

    pc.pageIndicatorTintColor= [UIColorgreenColor];// 一般关闭用户交互pc.userInteractionEnabled=NO;

    相关文章

      网友评论

        本文标题:ios UI控件的简单整理(4)

        本文链接:https://www.haomeiwen.com/subject/gxarzttx.html