纯代码实现图片预览
来源:互联网 发布:stl库string源码 编辑:程序博客网 时间:2024/04/29 14:56
1UI效果图
2.代码实现
//// ViewController.m// 04-图片浏览器//// Created by liuhang on 15/11/20.// Copyright © 2015年 liuhang. All rights reserved.//#import "ViewController.h"/* 1.查看界面元素需要哪些标签 UIImageView 图片显示 UIButton 按钮 UILabel 标签 @property 生成set和get 并生成员变量 _noLabel 2.代码布局 注意点 : UIImage 是图片,不是控件;他的父类为NSObject; UIImageView是加载图片的控件,父类为UIView 3.设置监听,实现功能 */@interface ViewController ()// 定义属性名称// 1.序号标签@property (nonatomic ,strong) UILabel *noLabel;// 2.图片按钮@property (nonatomic , strong) UIImageView *iconImage;// 3.文字描述标签@property (nonatomic , strong) UILabel *descLabel;// 4.左按钮@property (nonatomic , strong) UIButton *leftButton;// 5.右按钮@property (nonatomic , strong) UIButton *rightButton;@end@implementation ViewController// 初始化加载 : 在viveDidLoad创建界面- (void)viewDidLoad { [super viewDidLoad]; // 1.添加序号标签 slef.noLabel _noLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, 40)]; _noLabel.text = @"1/5"; // 设置文本内容 _noLabel.textAlignment = NSTextAlignmentCenter; NSLog(@"屏幕的宽度 = %f",self.view.bounds.size.width); // 414(6s) [self.view addSubview:_noLabel]; // 将视图添加到父视图 // 2.添加图片 CGFloat imageW = 200; CGFloat imageH = 200; // 图片居中,(获取屏幕长度 - 图片宽度) * 0.5 乘法的效率要不除法的效率高一点 CGFloat imageX = (self.view.bounds.size.width - imageW) * 0.5; // 高度比序号标签高30 CGFloat imageY = _noLabel.bounds.size.height + 30; _iconImage = [[UIImageView alloc] initWithFrame:CGRectMake(imageX, imageY, imageW, imageH)]; // _iconButton.backgroundColor = [UIColor redColor]; 设置背景颜色检测正确性 _iconImage.image = [UIImage imageNamed:@"biaoqingdi"]; // 设置背景图片 [self.view addSubview:_iconImage]; // 3.描述文字 // CGRectGetMaxY是获取当前控件y坐标值 + 控件高度的值 CGFloat descY = CGRectGetMaxY(self.iconImage.frame); _descLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, descY , self.view.bounds.size.width, 100)]; _descLabel.text = @"表情帝"; _descLabel.textColor = [UIColor redColor]; // 设置文本颜色 _descLabel.textAlignment = NSTextAlignmentCenter; [self.view addSubview:_descLabel]; // 4.添加左按钮 _leftButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)]; // 初始化按钮位置 // 动态设置按钮位置 CGFloat centerY = self.iconImage.center.y; CGFloat centerX = self.iconImage.center.x * 0.3; _leftButton.center = CGPointMake(centerX, centerY); // 按钮设置背景图片只能通过set方法 [_leftButton setBackgroundImage:[UIImage imageNamed:@"left_normal"] forState:UIControlStateNormal]; [_leftButton setBackgroundImage:[UIImage imageNamed:@"left_highlighted"] forState:UIControlStateHighlighted]; [self.view addSubview:_leftButton]; // 5.设置右按钮 _rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; _rightButton.center = CGPointMake(self.view.bounds.size.width - centerX, centerY); // 按钮设置背景图片只能通过set方法 [_rightButton setBackgroundImage:[UIImage imageNamed:@"right_normal"] forState:UIControlStateNormal]; [_rightButton setBackgroundImage:[UIImage imageNamed:@"right_highlighted"] forState:UIControlStateHighlighted]; [self.view addSubview:_rightButton];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- 纯代码实现图片预览
- 纯AS代码实现可预览本地图片的flash上传客户端(as3.0)
- [AS3]纯AS代码实现可预览本地图片的flash上传客户端
- 纯javascript实现图片上传前预览,判断图片大小
- 纯前端实现图片上传预览(filereader )
- javascript实现本地预览图片的代码
- 纯前端的图片预览
- 用纯ASP代码实现图片上传
- 纯CSS代码实现图片轮显
- 用纯ASP代码实现图片上传
- 纯代码无图片Tips实现过程
- JS图片预览代码
- js实现IE7图片上传预览的功能代码
- 上传图片实现预览功能的js代码
- 实现图片上传预览
- android实现图片预览
- HTML图片预览实现
- JS实现图片预览
- lightOJ 1148 - Mad Counting 【水题】
- Oracle数据关联查询
- 子线程循环10次,接着主线程循环100,接着又回到子线程循环10次,接着再回到主线程又循环100,如此循环50次
- Google C++ Testing Framework Primer
- NOI2008 志愿者招募
- 纯代码实现图片预览
- HTML5能为我们带来什么
- 我知道的xUtils
- 游戏作弊器制作教程二:键盘鼠标钩子
- beaglebone black 2G emmc 无盘符
- 取消线程的执行
- Mac AndroidStudio 错误
- bzoj 4318 osu 【三次方问题】【dp】
- SpringSecurity3.1入门教程(一)