这篇文章主要为大家详细介绍了iOS开发实现图片浏览功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了iOS实现图片浏览功能的具体代码,供大家参考,具体内容如下
这是整体的效果图:
其中main.stroyboard中的控件有2个button,2个label,一个imageView。
设置他们的位置大小和背景颜色和图片。
让main.storyboard连接ViewController.m
下面是它的代码:
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic, assign) int index;
@property (nonatomic, strong) NSArray *imageDicts;
@end
@implementation ViewController
- (NSArray *)imageDicts
{
if (!_imageDicts) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"imageDate.plist" ofType:nil];
_imageDicts = [NSArray arrayWithContentsOfFile:path];
}
return _imageDicts;
}
- (IBAction)leftBtnOnClick:(UIButton *)sender {
self.index --;
[self btnClickChange];
}
- (IBAction)rightBtnOnClick:(id)sender {
self.index ++;
[self btnClickChange];
}
- (void)btnClickChange
{
self.topLabel.text = [NSString stringWithFormat:@"%d/%d", (self.index + 1), self.imageDicts.count];
self.descLabel.text = self.imageDicts[self.index][@"description"];
self.imageView.image = [UIImage imageNamed:self.imageDicts[self.index][@"name"]];
self.leftBtn.enabled = (self.index != 0);
self.rightBtn.enabled = (self.index != 4);
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end这样就完成了一个简单的图片浏览的应用。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:iOS开发实现图片浏览功能
猜你喜欢
- Flutter实现底部和顶部导航栏 2022-08-31
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- iOS 对当前webView进行截屏的方法 2023-03-01
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- Android studio实现动态背景页面 2023-05-23
- Android实现轮询的三种方式 2023-02-17
- 详解flutter engine 那些没被释放的东西 2022-12-04
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
- Android实现监听音量的变化 2023-03-30
