iOS Development Static Library (v)--image, interface Xib and other resource files encapsulated into the static framework framework

Source: Internet
Author: User

Build Environment: Macbook Air + OS X 10.9.2 + XCode5.1 + iphone5s (iOS7.0.3)

First, the resource files are packaged into bundles

Since the bundle is static, the "Mytoolswithassetsa.bundle" file generated in the "Static Library of iOS development" (iii)-Picture, interface xib, etc., can be encapsulated directly in the. a static library.

Ii. Creating a static framework

Create a process reference "static Library of iOS development (iv)--static framework framework production", which is described in great detail.

Static library code borrowing "Static Library of iOS Development (iii)--Pictures, interface Xib and other resource files encapsulated in the. A static library" file

The code does not make any changes, directly using the

  bundletools.h//  mytoolswithassetsa////  Created by LZH on 14-8-15.//  Copyright (c) 2014 LZH. All rights reserved.//#import <Foundation/Foundation.h> #define BUNDLE_NAME @ "Mytoolswithassetsa" @interface bundletools:nsobject+ (NSString *) Getbundlepath: (NSString *) assetname;+ (NSBundle *) Getbundle; @end
  bundletools.m//  mytoolswithassetsa////  Created by LZH on 14-8-15.//  Copyright (c) 2014 LZH. All rights reserved.//#import "BundleTools.h" @implementation bundletools+ (NSBundle *) getbundle{        return [nsbundle Bundlewithpath: [[NSBundle Mainbundle] pathforresource:bundle_name ofType: @ "BUNDLE"];} + (NSString *) Getbundlepath: (NSString *) assetname{        nsbundle *mybundle = [Bundletools getbundle];        if (Mybundle && assetname) {                return [[Mybundle ResourcePath] stringbyappendingpathcomponent:assetname];< c12/>}        return nil;} @end
////viewcontroller1.h//mytoolswithassetsademo////Created by LZH on 14-8-15.// Copyright (c) 2014 LZH. All rights reserved.//#import <UIKit/UIKit.h> @interface viewcontroller1:uiviewcontroller@property (Strong, nonatomic) Uiimageview *imageview; @end 
viewcontroller1.m//mytoolswithassetsademo////Created by LZH on 14-8-15.//Copyright (c) 2014 LZH. All rights reserved.//#import "ViewController1.h" #import "BundleTools.h" #import <quartzcore/quartzcore.h>@ Interface ViewController1 () @end @implementation viewcontroller1@synthesize ImageView = _imageview;-(ID) init{Nsbun        Dle *mybundle = [Bundletools getbundle];    self = [Super Initwithnibname: @ "ViewController1" bundle:nil]; Get interface file from bundle self = [super Initwithnibname: [NSString stringwithutf8string:object_getclassname (self)] Bundle:mybu    Ndle]; if (self) {//Custom initialization} return to self;} -(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [Super Initwithnibname:nibnam    Eornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;}    -(void) viewdidload{[Super Viewdidload];        Do any additional setup after loading the view from its nib. _imAgeview = [[Uiimageview alloc] Initwithframe:cgrectmake (50, 100, 220, 220)];    _imageview.image = [UIImage imagenamed: @ "0001.jpg"];        Get the picture resource from the bundle _imageview.image = [UIImage imagewithcontentsoffile: [bundletools Getbundlepath: @ "0001.jpg]];    Add rounded corners to the picture _imageview.layer.cornerradius = 20;    _imageview.layer.maskstobounds = YES;    _imageview.layer.borderwidth = 3; _imageview.layer.bordercolor = [Uicolor Orangecolor].        Cgcolor;    [Self.view addsubview: _imageview]; }-(ibaction) Backbutton: (ID) Sender {[self dismissviewcontrolleranimated:yes completion:null];} @end

Adding source files and header files

Modify configuration options

Shortcut key "Command + B" compilation, build the framework of the real machine version and the simulator version respectively

Merge to generate a comprehensive version of the framework

Get ready for work!

III. Creation of Test engineering

Create a single view template

Project naming

Import Bundle Resource Bundle, the bundle here does not change the name, modify the place to use it to modify, steal lazy ...

Importing the framework static framework

Writing test Code

  viewcontroller.m//  mytoolswithassetsframeworktest////  Created by LZH on 14-8-21.//  Copyright ( c) 2014 LZH. All rights reserved.//#import "ViewController.h" #import <MyToolsWithAssets/ViewController1.h> @interface Viewcontroller () @end @implementation viewcontroller-(void) viewdidload{    [Super viewdidload];//do any additional Setup after loading the view, typically from a nib.} -(void) didreceivememorywarning{    [Super didreceivememorywarning];    Dispose of any resources the can be recreated.} Button response Function-(ibaction) buttonpressed: (ID) Sender {        ViewController1 *view1 = [[ViewController1 alloc] init];    View1.modaltransitionstyle = uimodaltransitionstylefliphorizontal;   Interface Toggle Animation effect    [self presentviewcontroller:view1 animated:yes completion:null];} @end

Shortcut key "Command + R" Run

Real machine version Run results try it yourself.

Emulator version Run result

--Over--

iOS Development Static Library (v)--image, interface Xib and other resource files encapsulated into the static framework framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.