iOS開發(fā)實(shí)現(xiàn)圖片瀏覽功能
本文實(shí)例為大家分享了iOS實(shí)現(xiàn)圖片瀏覽功能的具體代碼,供大家參考,具體內(nèi)容如下
這是整體的效果圖:

其中main.stroyboard中的控件有2個button,2個label,一個imageView。
設(shè)置他們的位置大小和背景顏色和圖片。
讓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這樣就完成了一個簡單的圖片瀏覽的應(yīng)用。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解決JSON數(shù)據(jù)因?yàn)閚ull導(dǎo)致數(shù)據(jù)加載失敗的方法
前段時間發(fā)現(xiàn)一個問題,當(dāng)JSON數(shù)據(jù)中有null會導(dǎo)致數(shù)據(jù)加載失敗,后來解決了,現(xiàn)在將解決方法分享給大家,有同樣問題的朋友們可以參考。下面來一起看看吧。2016-09-09
iOS端React Native差異化增量更新的實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于iOS端React Native差異化增量更新的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06
iOS中使用Fastlane實(shí)現(xiàn)自動化打包和發(fā)布
Fastlane是一套使用Ruby寫的自動化工具集,用于iOS和Android的自動化打包、發(fā)布等工作,可以節(jié)省大量的時間。下面給大家介紹ios fastlane 自動化打包和發(fā)布的安裝方法,需要的朋友參考下吧2017-05-05
IOS 開發(fā)之 UITextField限制字?jǐn)?shù)的方法
這篇文章主要介紹了IOS 開發(fā)之 UITextField限制字?jǐn)?shù)的方法的相關(guān)資料,這里提供實(shí)現(xiàn)限制最大字?jǐn)?shù)的方法,需要的朋友可以參考下2017-08-08

