iOS開發(fā)實現(xiàn)圖片瀏覽功能
本文實例為大家分享了iOS實現(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)文章
iOS開發(fā)實現(xiàn)搜索框(UISearchController)
這篇文章主要為大家詳細介紹了iOS開發(fā)實現(xiàn)搜索框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-08-08iOS開發(fā)檢測是否開啟定位、是否允許消息推送等權(quán)限的實例
下面小編就為大家分享一篇iOS開發(fā)檢測是否開啟定位、是否允許消息推送等權(quán)限的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01IOS 開發(fā)之swift中UIView的擴展使用的實例
這篇文章主要介紹了IOS 開發(fā)之swift中UIView的擴展使用的實例的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下2017-09-09