framework with view controller and storyboard - ios

Is it possible to create a cocoa touch framework in swift which contain storyboard and viewControllers?
If yes can you give me a reference to a guide or something to get started? all the examples i see of creating frameworks are very simple classes which don't involve ui
I want to create a framework which involve UI

Yes, that is possible.
All you have to do is to create a cocoa framework as you normally do from File > New > iOS - Cocoa Framework..
Since this involves UI, Click on the project and right click > New > iOS - Storyboard. And after that it is just as simple as you do it in a normal app. Once your stuff is over in the framework side, you gotta create a new project to test your framework with UI (make sure that the class created in fw is a public class ).
To load the storyboard of your framework instead of your sample project's storyboard, do the full in ViewWillAppear method.
Create an object for storyboard along with the bundle (of your framework - normally it will be your VC's name)
instantiateInitialViewController
And present them
And you'll have your framework's storyboard in your sample project.

Related

How to be able to use UI component from framework in Storyboard?

I would like to use an UIView subclass from an external framework in my project's Storyboard. I tried with different projects but each time I can't see the class name in the custom class dropdown menu.
Is it possible to make it work?
I guess the frameworks are fine, it should be an import/linking problem.
One thing could be that you are using a mix of swift and objective c like your project is in swift and your framework is in objective c in that case you need to add bridging header and import your .h files in it. It will work if that's the case

How to create an instance of UIView from Watch Extension in watch OS 2?

In watch OS 1, I was able to create an instance of a custom view in WatchExtension. I'm not talking about showing it, I mean just creating an instance of the view and then create an UIImage with its content.
Now, in watch OS 2, I can't access to the UIView from WatchExtension, even when I have imported the UIKit framework.
Is there any way to be able to create an instance of UIView from WatchExtension?
It seems it's not possible on watchOS2 unfortunately. While watchOS1 used the iOS platform SDK, watchOS2 is a separate platform.
migration docs:
In watchOS 2, you can share code, but not frameworks, between your iOS app and Watch app. Because the apps run on separate platforms with different architectures...
Also in WatchKit in depth 1 wwdc video they mention this:
The WatchKit extension for watchOS 1 is something you have created already, there is a target in your project, but it uses the iOS platform in SDK.
Here are the available system technologies you can use on watchOS2.
I did the same thing on watchOS1 like you, used a UIView and snapshotted it into a UIView. Besides doing this on the phone and sending it back to the watch (in which you loose the benefit of watchOS2 that the extension runs on the watch and doesn't need to communicate with the phone), or getting it as an image from a server, I don't see any other way of doing it.
edit: there is Core Graphics available so we are able to do basic drawings. See here: http://develop.watch/develop-for-watchos-2-iii-drawing/
No. In watch OS 2 you cannot dynamically allocate any UI element. You must use storyboard if you want to init any UI stuff.
Creating an Interface Object
You create interface objects indirectly by adding the object to your
storyboard scene and referring to it from your interface controller.
After adding an element to your storyboard, create an outlet for it in
your interface controller. During the initialization of your interface
controller, WatchKit creates the interface objects for all of your
connected outlets automatically. You never create the interface
objects yourself.

iOS8: Frameworks -- In storyboard referencing images from the App

I'm thinking about doing a Framework to share code between two apps. I would like to include a Storyboard with a View Controller that will reference an image inside the App.
For example: In the Framework, the UIImageView in the View Controller will reference an image called "Car", however, the image will not be included in the Framework. The App consuming the Framework will provide Car.PNG
Question 1: Is this possible?
Question 2: Can I reference the image in Storyboard Interface Builder under attribute inspector? or do I have to do it in code?
Question 3: Do I need to do anything special, i.e. provide the bundle or anything?

Static library, bundle and IB Designable

I'm trying to use the IB Designable and IB Inspectable in my UIButton but seems there are some errors.
In the Issue Navigator, the bundle file:
Storyboard :
IB Designables : Failed to update auto layout status: Failed to load designabled from path (null)
So I wonder if there are any configurations to do to use it in a static lib or something like that ?
This is
#import <UIKit/UIKit.h>
IB_DESIGNABLE
#interface CustomUIButton : UIButton
#property (nonatomic) IBInspectable int cornerRadius;
#end
My custom button I want to live render is inside a view controller
Unfortunately it isn't possible to use IBDesignables with static libraries (or static frameworks).
This isn't a great answer but I want to give some context on why.
It seems that the way Interface Builder loads classes to be shown as designables is by actually dynamically loading the dynamic framework that you create (and not your app's binary), and using the classes directly (after changing them using the Objective-C runtime quite a bit).
You can see that Interface Builder isn't loading your app, and just the individual frameworks with these steps:
Create a new Xcode project
Create a new framework target in the project
Add a class that is IBDesignable
In the storyboard from your app create a view and set its class to your framework's IBDesignable class
Click "Refresh All Views" in the "Editor" menu
In your DerivedData folder for the project, in the IBDesignables directory, you can see that only your framework target has been built.
Interface builder actually loads your framework using dlopen manually. You can also see that to facilitate this when building your framework, Interface Builder actually adds 2 RPATHs to your binary, so the dependencies can be found in the custom paths (you can view this with otool -L frameworkbinary). This method of loading your binary isn't possible with static libraries.
For what it's worth I think the best workaround for this is to build dynamic frameworks, instead of static libraries, but only for IBDesignable builds. You'll have to do some configuration work to do this, and it isn't easy to work around Xcode to have this work, but if you try it, you can use either the build path, or the environment, to differentiate IBDesignable builds vs "normal" builds.
EDIT: IB Designable and IB Inspectable do not seem to work with static libraries, so if you're using a static library, either consider using a dynamic framework (iOS 8 only) or move your component outside the static library, if possible.
For issues related with Cocoapods, use the following solution:
This is related to this question.
Here's the solution:
1) Install Cocoapods (0.36.0.beta.1) or newer;
2) Add use_frameworks! to your Podfile
See more here.

How to create an iOS project with a XIB in XCode 5

I'm running xcode 5.0.1. In previous version Xcode, there was to be a checkbox for not using storyboard when creating a ios project. How do I turn off storyboards and just use xib files in xcode 5.0.1?
Unfortunately, the built-in project templates in Xcode 5 mandate storyboards, unless you pick the Empty Application template. Your choices therefore boil down to:
Start every project as an Empty Application and add your view controllers from the ground up
Start using one of the storyboard-based templates, then:
Delete the storyboard file
Change the main storyboard setting in your project to be empty
Add .xibs to the existing view controllers as needed
Implement your app delegate methods as needed to set up a view controller hierarchy
Open a new project as an empty project. The selection is in the bottom row, second from the right. Then you can add your view controllers in your app delegate. Hope this helps.

Resources