iOS学习(UI)知识点整理一、关于UIButton的介绍1)概念:UIButton 是一种常用的控件,通过点击触发相应的功能 2)UIButton 的几种常用的状态 1、UIControlStateNormal 正常状态 ...
iOS学习(UI)知识点整理
一、关于UIButton的介绍1)概念:UIButton 是一种常用的控件,通过点击触发相应的功能 2)UIButton 的几种常用的状态3)UIButton常用的几种事件4)UIButton 初始化实例代码
1 UIButton *button = [[UIButton alloc] init]; 2 button.frame = CGRectMake(20, 50, 50 , 50); 3 button.backgroundColor = [UIColor clearColor]; 4 [button setTitle:@"按钮1 正常状态" forState:UIControlStateNormal]; 5 [button setTitle:@"按钮1 高亮状态" forState:UIControlStateHighlighted]; 6 [button setTitle:@"按钮1 选中状态" forState:UIControlStateSelected]; 7 8 //按钮点击时触发事件 9 [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];10 //按钮按下后触发事件11 [button addTarget:self action:@selector(buttonTappedDown:) forControlEvents:UIControlEventTouchDown];12 //按钮双击触发事件13 [button addTarget:self action:@selector(buttonTappedDown:) forControlEvents:UIControlEventTouchDownRepeat];14 //设置按钮高亮状态下的字体颜色15 [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];16 //button字体变为35号加粗的字体17 button.titleLabel.font = [UIFont boldSystemFontOfSize:35];18 //设置圆角 19 button.layer.cornerRadius = 5.f;20 //设置边框宽度21 button.layer.borderWidth = 2.1;22 //设置边框颜色23 button.layer.borderColor = [UIColor lightGrayColor].CGColor;24 //设置按钮背景图 25 UIImage *imageNormal = [UIImage imageNamed:@"camera"];26 //设置imageNormal为按钮的正常情况的图片27 [button setImage:imageNormal forState:UIControlStateNormal];28 29 UIImage *imageHightLight = [UIImage imageNamed:@"camera2"];30 //设置imageHightLight为按钮的高亮情况的图片31 [button setImage:imageHightLight forState:UIControlStateHighlighted];32 //当button设置了图片的时候 并且没有设置高亮状态下得图片,取消高亮状态, 默认是Yes33 button.adjustsImageWhenHighlighted = YES; 34 [self.window addSubview:button];
1)概念:UIImageView 是iOS中专门用于展示图片的控件2)UIImageView 初始化 实例代码
1 UIImageView *imageView = [[UIImageView alloc] init]; 2 imageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width); 3 imageView.backgroundColor = [UIColor whiteColor]; 4 imageView.center = self.view.center; 5 6 //tag设置控件的唯一标识,值不能重复 7 imageView.tag = 100; 8 9 //UIImageView的 clipsToBounds属性,设置为yes的时候超出部分,不予以显示10 imageView.clipsToBounds = YES;11 12 //读取一张图片13 UIImage *image = [UIImage imageNamed:@"icon"];14 imageView.image = image;15 16 //设置图片展示模式17 imageView.contentMode = UIViewContentModeScaleAspectFill;18 19 //打开imageview的用户交互 注:要实现图片点击事件此属性必须设置为YES20 imageView.userInteractionEnabled = YES;21 [self.view addSubview:imageView];22 23 //为UIImageView添加点击事件 24 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self 4)UITapGestureRecognizer 除了可以给UI_ImageView添加点击方法外还可以给其他控件添加点击方法 5)iOS中获取图片的三种方法
原标题:iOS阶段学习第27天笔记(UIButton
关键词:IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。