最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IOS 應(yīng)用程序管理的實現(xiàn)

 更新時間:2017年10月09日 09:05:27   投稿:lqh  
這篇文章主要介紹了IOS 應(yīng)用程序管理的實現(xiàn)的相關(guān)資料,希望通過本文能幫助到大家,讓大家實現(xiàn)這樣的功能,需要的朋友可以參考下

IOS 應(yīng)用程序管理的實現(xiàn)

1. 項目名稱:應(yīng)用管理

2. 項目截圖展示

3. 項目功能

展示應(yīng)用圖標(biāo),名稱和下載按鈕

點擊下載按鈕,出現(xiàn)“正在下載”圖標(biāo)

4. 項目代碼

模型代碼:AppInfo.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface AppInfo : NSObject

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *icon;

@property (nonatomic, strong, readonly) UIImage *image;

/** 使用字典實例化模型 */
- (instancetype)initWithDict:(NSDictionary *)dict;

/** 快速實例化一個對象 */
+ (instancetype)appInfoWithDict:(NSDictionary *)dict;

/** 返回所有plist中的數(shù)據(jù)模型數(shù)組 */
+ (NSArray *)appList;


@end

模型代碼:AppInfo.m

#import "AppInfo.h"

@implementation AppInfo

// 合成指令,主動指定屬性使用的成員變量名稱
@synthesize image = _image;

//圖片模型
- (UIImage *)image
{
  if (_image == nil) {
    _image = [UIImage imageNamed:self.icon];
  }
  return _image;
}

- (instancetype)initWithDict:(NSDictionary *)dict
{

  self = [super init];
  if (self) {
    // 用字典給屬性賦值
    //    self.name = dict[@"name"]; //將字典的內(nèi)容賦值給屬性
    //    self.icon = dict[@"icon"];
    [self setValuesForKeysWithDictionary:dict];
  }
  return self;
}

+ (instancetype)appInfoWithDict:(NSDictionary *)dict
{
  return [[self alloc] initWithDict:dict];
}

+ (NSArray *)appList
{
  NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil]];

  // 創(chuàng)建一個臨時可變數(shù)組
  NSMutableArray *arrayM = [NSMutableArray array];

  // 遍歷數(shù)組,依次轉(zhuǎn)換模型
  for (NSDictionary *dict in array) {
    [arrayM addObject:[AppInfo appInfoWithDict:dict]];
  }

  return arrayM;
}

@end

模型View:AppView.h

#import <UIKit/UIKit.h>

@class AppInfo;

@interface AppView : UIView

/** 類方法,方便調(diào)用視圖 */
+ (instancetype)appView;

/** 實例化視圖,并使用appInfo設(shè)置視圖的顯示 */
+ (instancetype)appViewWithAppInfo:(AppInfo *)appInfo;

// 自定義視圖中顯示的數(shù)據(jù)來源是數(shù)據(jù)模型
// 使用模型設(shè)置自定義視圖的顯示
@property (nonatomic, strong) AppInfo *appInfo;

@end

模型View:AppView.m

#import "AppView.h"
#import "AppInfo.h"

@interface AppView()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *label;

@end

@implementation AppView

//實例化xib
+ (instancetype)appView
{
  return [[[NSBundle mainBundle] loadNibNamed:@"AppView" owner:nil options:nil] lastObject];
}

//根據(jù)模型實例化xib
+ (instancetype)appViewWithAppInfo:(AppInfo *)appInfo
{
  // 1. 實例化一個視圖
  AppView *view = [self appView];

  // 2. 設(shè)置視圖的顯示
  view.appInfo = appInfo;//包含,AppView有appInfo的屬性

  // 3. 返回視圖
  return view;
}

/**
 利用setter方法設(shè)置視圖的界面顯示
 */
- (void)setAppInfo:(AppInfo *)appInfo
{
  _appInfo = appInfo;

  self.label.text = appInfo.name;
  self.iconView.image = appInfo.image;
}

/** 按鈕監(jiān)聽方法 */
- (IBAction)click:(UIButton *)button
{
  // 添加一個UILabel到界面上
  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80, 400, 160, 40)];
  // 數(shù)值是0表示黑色,1表示純白;alpha表示透明度
  label.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];

  label.text = self.appInfo.name;
  label.textAlignment = NSTextAlignmentCenter;

  // self.superview就是視圖控制器中的self.view
  [self.superview addSubview:label];

  // 動畫效果
  label.alpha = 0.0;

  // 禁用按鈕,如果點擊了按鈕以后就禁用按鈕
  button.enabled = NO;

  // 動畫結(jié)束之后刪除
  [UIView animateWithDuration:1.0f animations:^{
    // 要修改的動畫屬性
    label.alpha = 1.0;
  } completion:^(BOOL finished) {
    [UIView animateWithDuration:1.0 animations:^{
      label.alpha = 0.0;
    } completion:^(BOOL finished) 
      [label removeFromSuperview];
    }];
  }];
}

@end

ViewController.m

#import "ViewController.h"
#import "AppInfo.h"
#import "AppView.h"

#define kAppViewW 80
#define kAppViewH 90
#define kColCount 3
#define kStartY  20

@interface ViewController ()

/** 應(yīng)用程序列表 */
@property (nonatomic, strong) NSArray *appList;

@end

@implementation ViewController


- (NSArray *)appList
{
  if (_appList == nil) {
    _appList = [AppInfo appList];
  }
  return _appList;
}

- (void)viewDidLoad
{
  [super viewDidLoad];

  // 搭建九宮格
  // 320 - 3 * 80 = 80 / 4 = 20
  CGFloat marginX = (self.view.bounds.size.width - kColCount * kAppViewW) / (kColCount + 1);
  CGFloat marginY = 10;

  for (int i = 0; i < self.appList.count; i++) {

    // 行
    int row = i / kColCount;

    // 列
    int col = i % kColCount;

    CGFloat x = marginX + col * (marginX + kAppViewW);
    CGFloat y = kStartY + marginY + row * (marginY + kAppViewH);

    //加載第i個xib視圖
    AppView *appView = [AppView appViewWithAppInfo:self.appList[i]];

    // 設(shè)置視圖位置
    appView.frame = CGRectMake(x, y, kAppViewW, kAppViewH);

    [self.view addSubview:appView];

    }
}

5. 本項目必須掌握的代碼段

字典轉(zhuǎn)模型

- (instancetype)initWithDict:(NSDictionary *)dict
{
  self = [super init];
  if (self) {
    [self setValuesForKeysWithDictionary:dict];
  }
  return self;
}

+ (instancetype)appInfoWithDict:(NSDictionary *)dict
{
  return [[self alloc] initWithDict:dict];
}

+ (NSArray *)appList
{
  NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil]];

  // 創(chuàng)建一個臨時可變數(shù)組
  NSMutableArray *arrayM = [NSMutableArray array];

  // 遍歷數(shù)組,依次轉(zhuǎn)換模型
  for (NSDictionary *dict in array) {

    [arrayM addObject:[AppInfo appInfoWithDict:dict]];
  }

  return arrayM;
}

KVC

 [self setValuesForKeysWithDictionary:dict];

6. 筆記

字典轉(zhuǎn)模型:

plist文件有多個字典,把字典的元素轉(zhuǎn)換成模型類對象的成員變量,將模型類對象放入數(shù)組中 模型的屬性名稱和plist文件中的key名稱必須一致

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • iOS實現(xiàn)簡易的導(dǎo)航欄顏色漸變實例代碼

    iOS實現(xiàn)簡易的導(dǎo)航欄顏色漸變實例代碼

    很多APP 都有導(dǎo)航欄顏色漸變的效果,下面這篇文章主要給大家介紹了關(guān)于iOS如何實現(xiàn)簡易的導(dǎo)航欄顏色漸變效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧
    2018-10-10
  • iOS底層探索之自動釋放池原理解析

    iOS底層探索之自動釋放池原理解析

    這篇文章主要介紹了iOS底層探索之自動釋放池,自動釋放池的壓棧和出棧,通過結(jié)構(gòu)體的構(gòu)造函數(shù)和析構(gòu)函數(shù)觸發(fā),自動釋放池的本質(zhì)是__AtAutoreleasePool結(jié)構(gòu)體,包含構(gòu)造函數(shù)和析構(gòu)函數(shù),本文通過示例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2022-06-06
  • iOS時間字符串格式化輸出技巧詳解

    iOS時間字符串格式化輸出技巧詳解

    本篇文章主要介紹了iOS時間格式化輸出技巧,可以將后臺返回的時間字符串轉(zhuǎn)換為指定的格式時間再顯示在UI上,有興趣的可以了解一下。
    2017-04-04
  • IOS獲取當(dāng)前版本號 Bundle ID等信息的方法詳解

    IOS獲取當(dāng)前版本號 Bundle ID等信息的方法詳解

    這篇文章主要介紹了IOS獲取當(dāng)前版本號 Bundle ID等信息的方法詳解的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • iOS讀取txt文件出現(xiàn)中文亂碼的解決方法

    iOS讀取txt文件出現(xiàn)中文亂碼的解決方法

    這篇文章主要為大家詳細(xì)介紹了iOS讀取txt文件出現(xiàn)中文亂碼的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • iOS中自帶超強中文分詞器的實現(xiàn)方法

    iOS中自帶超強中文分詞器的實現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于iOS中自帶超強中文分詞器的實現(xiàn)方法,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2017-06-06
  • 超全的iOS各種設(shè)備信息獲取方法總結(jié)(包括iPhone8/iPhone X)

    超全的iOS各種設(shè)備信息獲取方法總結(jié)(包括iPhone8/iPhone X)

    這篇文章主要給大家介紹了關(guān)于iOS各種設(shè)備信息獲取方法,iPhone8/iPhone X的后驅(qū)詳細(xì)信息也已更新,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • iOS開發(fā)中對于攝像頭的一些基本使用方法分享

    iOS開發(fā)中對于攝像頭的一些基本使用方法分享

    這篇文章主要介紹了iOS開發(fā)中對于攝像頭的一些基本使用方法分享,包括判斷攝像頭是否可用的方法,需要的朋友可以參考下
    2015-10-10
  • iOS10 推送完整剖析和注意事項

    iOS10 推送完整剖析和注意事項

    這篇文章主要為大家詳細(xì)介紹了iOS10 推送完整剖析和注意事項,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • 總結(jié)iOS App開發(fā)中控制屏幕旋轉(zhuǎn)的幾種方式

    總結(jié)iOS App開發(fā)中控制屏幕旋轉(zhuǎn)的幾種方式

    這篇文章主要介紹了iOS app開發(fā)中控制屏幕旋轉(zhuǎn)的方法總結(jié),分為自動旋轉(zhuǎn)和手動旋轉(zhuǎn)以及強制旋轉(zhuǎn)三種情況,代碼為Objective-C語言,需要的朋友可以參考下
    2016-02-02

最新評論

修武县| 濮阳县| 淮北市| 永泰县| 武穴市| 甘谷县| 尉犁县| 曲水县| 理塘县| 庆云县| 顺平县| 汉阴县| 大冶市| 东宁县| 随州市| 游戏| 沁阳市| 营山县| 新津县| 洞头县| 宁强县| 汤阴县| 贵德县| 漳州市| 丘北县| 镶黄旗| 宜兰市| 武宁县| 加查县| 无极县| 松江区| 五指山市| 永和县| 信宜市| 孟村| 鹰潭市| 海门市| 全南县| 永春县| 昆山市| 芷江|