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

效果:

相关推荐
黑科技iOS上架8 小时前
iOS4.3合规自测手段:二进制分析
flutter·ios·cocoa·审核
网易易盾1 天前
iOS 设备环境核验接入实践:从特征扫描到运行时完整性识别
ios
布莱克6052 天前
Swift 自动引用计数(ARC)详解:原理、循环引用与最佳实践
开发语言·ios·swift·arc·自动引用计数
软件交付观察室2 天前
用户关掉手机定位权限后,原生App还能显示哪些位置?
android·ios·移动开发
KevinWang_4 天前
iOS 开发计划(一) - 通过 Scriptable app 在 iOS 上运行 JavaScript 脚本
javascript·ios
布莱克6054 天前
Swift 下标(Subscript)详解:从语法到实战
服务器·开发语言·ios·ssh·swift·下标
茶底世界之下5 天前
雨天的窗边:用 Awaking 轻轻提亮一盆蕨
ios·app·产品
景彬6 天前
强制升级 Xcode 后,一个 10 年老项目有哪些改动点
ios
茶底世界之下6 天前
海边书店的阴天:用 Awaking 留住青绿与暖灯
ios·app·产品
布莱克6057 天前
Swift 类详解:从定义、继承到内存管理的完整指南
服务器·开发语言·ios·ssh·swift·类