ios使用plist实现相册功能

第一步:照片复制到Assets文件夹再创建plist

第二步:页面设计

第三步:代码实现

objectivec 复制代码
//
//  PhotoViewController.m
//  study2024
//
//  Created by zhifei  zhu on 2024/8/11.
//

#import "PhotoViewController.h"

@interface PhotoViewController ()
@property (weak, nonatomic) IBOutlet UIButton *btnPre;
@property (weak, nonatomic) IBOutlet UIButton *btnNext;
@property (weak, nonatomic) IBOutlet UIImageView *img;
@property (weak, nonatomic) IBOutlet UILabel *lblTitle;
@property (weak, nonatomic) IBOutlet UILabel *lblDescrible;
@property (weak,nonatomic) NSArray *picArr;
@property (nonatomic) int index;
- (IBAction)pre:(id)sender;
- (IBAction)next:(id)sender;

-(void) getImagewithIndex:(int)index;
@end

@implementation PhotoViewController
-(NSArray *)picArr{
    if(_picArr==nil)
    {
        NSString *path=[[NSBundle mainBundle]pathForResource:@"pic.plist" ofType:nil];
        _picArr=[NSArray arrayWithContentsOfFile:path];
    }
    return _picArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self getImagewithIndex:0];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



- (IBAction)pre:(id)sender {
    self.index--;
    [self getImagewithIndex:self.index];
}
- (IBAction)next:(id)sender {
    self.index++;
    [self getImagewithIndex:self.index];
    
  
}

-(void) getImagewithIndex:(int)index{
    NSDictionary *dictionary=self.picArr[index];
    self.lblTitle.text=[NSString stringWithFormat:@"%d/%d",index+1,_picArr.count];
    self.lblDescrible.text=dictionary[@"title"];
    self.img.image=[UIImage imageNamed:dictionary[@"icon"]];
    self.btnPre.enabled=(index!=0);
    self.btnNext.enabled=(index!=(self.picArr.count-1));

}
@end

效果:

相关推荐
前端小超超27 分钟前
如何配置capacitor 打包的ios app固定竖屏展示?
前端·ios·web app
CocoaKier30 分钟前
AI让35岁程序员再次伟大
ios·微信小程序·aigc
库奇噜啦呼1 小时前
【iOS】单例模式
ios·单例模式
2501_915909061 小时前
苹果上架App软件全流程指南:iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传与审核技巧详解
android·ios·小程序·https·uni-app·iphone·webview
2501_915921431 小时前
iOS 文件管理与能耗调试结合实战 如何查看缓存文件、优化电池消耗、分析App使用记录(uni-app开发与性能优化必备指南)
android·ios·缓存·小程序·uni-app·iphone·webview
2501_915918412 小时前
App 苹果 上架全流程解析 iOS 应用发布步骤、App Store 上架流程
android·ios·小程序·https·uni-app·iphone·webview
库奇噜啦呼2 小时前
【iOS】UIViewController生命周期
macos·ios·cocoa
2501_916007472 小时前
苹果上架全流程详解,iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传与审核要点完整指南
android·ios·小程序·https·uni-app·iphone·webview
YungFan3 小时前
iOS26适配指南之UISlider
ios·swift
2501_915921433 小时前
iOS App 性能监控与优化实战 如何监控CPU、GPU、内存、帧率、耗电情况并提升用户体验(uni-app iOS开发调试必备指南)
android·ios·小程序·uni-app·iphone·webview·ux