UIImageview
2015-11-16 00:00
274 查看
摘要: 关于图片(实例、高亮、放大、缩小);
- (void)viewDidLoad { [super viewDidLoad]; // 页面颜色 self.view.backgroundColor = [UIColor yellowColor]; [[UIScreen mainScreen]bounds]; // 实例化 UIImageView *ImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 200, 100)]; // 实例并提取图片 UIImageView *ImageViewI = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"6"]]; // 实例后提取图片 ImageView.image =[UIImage imageNamed:@"1" ]; ImageViewI.frame =CGRectMake(10,125 , 350, 100); // 同时实力两张图片 _ImageViewII =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"11"] highlightedImage:[UIImage imageNamed:@"7"]]; _ImageViewII.frame =CGRectMake(10, 300,350, 100); [ self.view addSubview : ImageView ]; [ self.view addSubview : ImageViewI ]; [ self.view addSubview : _ImageViewII ]; // 设置按钮 UIButton *Button = [[UIButton alloc]initWithFrame:CGRectMake(40, 400, 100, 40)]; [Button setTitle:@"高亮切换" forState: UIControlStateNormal]; Button.backgroundColor = [UIColor purpleColor]; [Button addTarget:self action:@selector(gaoliang) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:Button]; // 设置图片决定字符大小;方法的设定; _ImageViewIII= [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"6"]]; _ImageViewIII.frame = CGRectMake(250, 500, 150, 100); [self.view addSubview:_ImageViewIII]; UIButton *buttonBig = [[UIButton alloc]initWithFrame:CGRectMake(200,500 , 50, 50)]; buttonBig.backgroundColor = [UIColor redColor]; [buttonBig setTitle:@"放大" forState:UIControlStateNormal]; [buttonBig addTarget:self action:@selector(Big) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:buttonBig]; UIButton *buttonSmall = [[UIButton alloc]initWithFrame:CGRectMake(200, 550, 50, 50)]; buttonSmall.backgroundColor = [UIColor blackColor]; [buttonSmall setTitle:@"缩小" forState:UIControlStateNormal]; [buttonSmall addTarget:self action:@selector(Small) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:buttonSmall]; _ImageViewIIII = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 200)]; [self.view addSubview:_ImageViewIIII]; _ImageViewset = [[UIImageView alloc]initWithFrame:CGRectMake(10, 500, 140, 100)]; _ImageViewset.image = [UIImage imageNamed:@"17"]; [self.view addSubview:_ImageViewset]; UIButton *ButtonUp = [[UIButton alloc]initWithFrame:CGRectMake(10, 600,80, 50)]; ButtonUp.backgroundColor = [UIColor redColor]; [ButtonUp setTitle:@"变大" forState:UIControlStateNormal]; [ButtonUp addTarget:self action:@selector(bianda) forControlEvents:UIControlEventTouchUpInside]; ButtonUp.backgroundColor = [UIColor purpleColor]; UIButton *ButtonDown = [[UIButton alloc]initWithFrame:CGRectMake(80, 600,70, 50)]; ButtonDown.backgroundColor = [UIColor blackColor]; [ButtonDown setTitle:@"变小" forState:UIControlStateNormal]; [ ButtonDown addTarget:self action:@selector(suoxiao) forControlEvents:UIControlEventTouchUpInside ]; [self.view addSubview:ButtonUp]; [self.view addSubview:ButtonDown]; } - ( void )gaoliang{ if (_ImageViewII.highlighted ==YES) { _ImageViewII.highlighted =NO; } else { _ImageViewII.highlighted =YES; } } - (void)Big{ _ImageViewIII.transform =CGAffineTransformMakeScale(4.5, 4.5); } - ( void )Small{ _ImageViewIII.transform =CGAffineTransformMakeScale(2.3, 4.5); } - ( void )bianda{ CGRect bonus = _ImageViewIIII.bounds; bonus.size.width += 50; bonus.size.height += 50; _ImageViewIIII.bounds = bonus; } - ( void )suoxiao{ NSLog(@"suoxiao"); CGRect frame= _ImageViewset.frame; NSLog(@"------%f",frame.size.width); frame.size.height -= 30; frame.size.width -= 30; _ImageViewset.frame=frame; NSLog(@"++++%f",frame.size.width); }
相关文章推荐
- UIView之【UIViewContentMode】
- UITextField leftView 光标的边距 监听return键 字符长度的限制 以及其他的常用方法
- LeetCode Range Sum Query - Immutable
- OPEN CASCADE Curve Continuity
- UpdateData(TRUE)与 UpdateData(FALSE);
- iOS Crash: dwarfdump 检查 UUID
- Jquerry
- lightOJ 1082 - Array Queries 【线段树(求最小值)】
- 2012 Asia Tianjin Regional Contest - Queue Sequence
- xcodebuild和xcrun的打包
- hdoj 2817 A sequence of numbers 【快速幂】
- jEasyUI1.3.6版API中文版(Richie696)
- IOS UIStepper
- IOS UIPickerView
- MIUI系统的一个问题
- Range Sum Query - Immutable from Leetcode
- IOS UIPickerView
- 如何通过 Vue+Webpack 来做通用的前端组件化架构设计
- Machine Learning week 2 quiz: programming assignment-Linear Regression
- CodeForces 527D Clique Problem 树状数组