IBDesignable controls in a framework - ios

I've watched the excellent video on IBDesignable https://developer.apple.com/videos/play/wwdc2014-411/ and have created a framework with a control in, to be used by my main app (and shared, if necessary).
I've created a custom 'composite' control using IB, as per this great tutorial, http://supereasyapps.com/blog/2014/12/15/create-an-ibdesignable-uiview-subclass-with-code-from-an-xib-file-in-xcode-6
The technique works well and I can now place my designable controls on my storyboard.
The problem is that I notice that all my IBOutlets and IBActions in my 'framework' appear in IB on my storyboard. But I wish to hide them! The functionality for the controls is hidden within the framework and the IBOutlets and IBActions have been created as such to facilitate their operation within that framework, with notification to the outside-world being handled via delegates or some other means.
This technique is compelling in that I can use it to create a reusable library of 'composite' controls but it would be useful to hide certain IBOutlets and IBActions from the library's implementors to ensure an element of 'security'
Can this be done?
Are there any flags to hide IBOutlet/IBAction elements within the framework?

When you speak of security, if you declare of #IBActions, #IBOutlets etc... as Internal, then they're private to your App's module.
In terms of frameworks, they consist of their own module (check in build settings, Module Name) and make sure "defines module" is enabled.
This ensures that your module is for starters "enabled" i.e. everything in your Framework (or app, or bundle which have their own modules defined) have their own environment.
From there, make sure that you've used the correct privacy when it comes to declarations:
Access control is explained is better detail here:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html

Related

Customize storyboards bundled inside iOS Framework file

I have a framework which has storyboard and xib files.
How do I make the storyboards within the framework customizable? i.e. people using my framework should be able to modify the storyboards to customize the look & feel.
When I imported my framework in another app project in XCode, I did not see the storyboard files within my framework. How to make them visible & editable?
Is it even advisable to use framework in this case or should I go with static library+resource bundles combination?
I finally did this,
Load custom xibs,storyboards dynamically. i.e. first try loading custom storyboards, if not present load default storyboard(use try catch to check).
Expose all viewcontroller outlets and event handling functions through header files.
Make connections between buttons in your custom framework and these header file outlets,event handlers. Done! Your Viewcontroller.m functions will be called on clicking on those buttons.

Xamarin DesignTime Custom Controls Render in XCode, edit control properties in DesignTime

I am developing an application on Xamarin.iOS and MvvmCross platforms. I use xib files instead of storyboards for design interfaces (navigation in my app based on ViewModels). How can I use Xcode's Interface Builder to render my custom controls & edit properties in IB?
Adding attributes [DesignTimeVisible (true)] for class and [Export ("Counter"), Browsable (true)] for properties does not work for XCode Interface Builder.
As far as I know in Objective-C classes there must be set #IBDesignable & #IBInspectable, if you want design time support in Xcode for custom controls.
I believe this is not possible with XCode Interface Builder since it needs to build the custom control in order to present it. And the XCode project generated by Xamarin is not buildable it is used only to track changes and generate C# code.
However you can take a look at the Xamarin Studio’s iOS designer. I think it has the feature you need.
Not exactly what you asked for but Xamarin do support basically the same thing, only using their iOS designer (which I have found rather flaky...)
https://developer.xamarin.com/guides/ios/user_interface/designer/ios_designable_controls_walkthrough/
edit: I just noticed the guy above also gave the same solution, his link is to the designer docs, mine is to the custom properties walkthrough so i'll leave it up :)

Dynamic Storyboard or Xibs/Nibs

Our company is developing a quite large app for the iPad. Eventually we want to be able to customize the UI per customer (tenant) and maybe even per user (of that customer). We started off in HTML5 but are moving to native.
I've done some reading on downloading XML from the server (or even generated XIB/NIB files) and dynamically adding those to your app.
Now with iOS 5 (and even further in 6) storyboarding is playing a big role.
My questions:
- Would it be better to use (multiple?) storyboards or XIBs?
- What are my options for both if I want to deliver a dynamic user interface?
I'm not looking for a magic pill, nor a discussion on HTML5 vs native, just some information on how I could deliver a dynamic interface and what techniques could help in doing so.
my response to your two questions is:
storyboard is great for scene management; it creates a visual connection between
your various scenes/views. i prefer to use storyboard for as much of my UI as possible.
however, there are elements that i have in some apps that pick up existing or reusable
or otherwise dynamic XIBs. i simply tie these together with my storyboards by loading
the XIBs in code at the location at which i want them. so, my ultimate answer for your
first question is "both", where storyboards are used where possible, and XIBs used for
dynamic scenes/views.
your options for dynamic user interface include at least the following two options (of which, as stated above, i prefer the second):
create all code using XIB files, and perform all UI transitions without storyboards
in code
create as much UI as you know will remain relatively static in terms of relationships
between viewControllers with storyboard, and then load the dynamic parts of the UI
using initWithNibName:bundle:
finally, you can use multiple storyboards if the situation warrants, and this could even apply to dynamic UI, whether it comes from re-usable components created elsewhere in storyboard and maintained separately, or storyboard XML (if you look at storyboard source, it is just XML under the hood) whether acquired from something that generated or wherever. you can even decide to manage your UI with multiple storyboards at the design phase if your app will have several complicated interconnected view-controller scenes (e.g. each tab in a UITabBarController may have its own storyboard, where each storyboard's scene rootController is connected/loaded when a tab is chosen).
StoryBoard all the way! I use to absolutely dislike storyboards, but then i got use to them and now i love them. Storyboards are the way to go.
Layout seems a really powerful framework for developing dynamic GUIs on iOS.
DISCLAIMER: I'm not the author of that framework; the author is Nick Lockwood, who seems to have an account here on SO. I found both this question and Nick Lockwood's Layout framework by googling "ios dynamic gui".
I haven't tried it yet, but it looks really promising.
The project is even hosted at GitHub here, and it has a MIT license.

using iOS static library common view controller in storyboard?

We are in the process of creating a set of common components and common views that are reusable across several applications we have. In these libraries we have the .xib files and view controllers. We want to be able to use these in storyboards for the specific applications. Is this even possible?
I haven't seen an easy way to share reusable views or components from static libraries in storyboards yet.
Whats the recommended way to do this to keep from having code duplicated in every project?
Thanks..
Typically when making a static library for sharing, you can also include a bundle with resources (xib and image files for instance). Take a look at the FacebookSDK for instance. It contains a bundle with images and strings. Those can be loaded by the SDK code or the client app of the SDK.
For help on making a static lib with resources, see : https://github.com/jverkoey/iOS-Framework (thanks #jnjosh) or https://github.com/kstenerud/iOS-Universal-Framework. I've used the iOS-Universal-Framework on a shipping app recently. Works well.
In order to use xib files with storyboards, you can take one of two approaches:
Load the xib View Controllers in an action or segue called by the VC in the storyboard.
Or use the xib within the storyboard. See: Using XCode storyboard to instantiate view controller that uses XIB for its design
Also if it's just for internal use, I recommend simply making a shared repository of code + resources, rather than making a static library. The main benefit of the static library is ease of distribution outside of your team.

Maintaining different localized versions of interface NIB files

I'm learning the basics steps to internationalize an app and I have a question about localizing interface NIB files... I've seen that in Xcode you can click on a AppViewController.xib interface file and click on the + in the Localization section of the inspector window to add another language along with the default English one (I add Italian for example)... This allows me to translate the interface in Italian... but then how do you maintain future evolution of the App? If you need to add a button, for example, you have to add it by hand to all the localized versions of your interface NIB file? Documentation says also
Objects in a nib file typically have connections between them that should not be broken. Make sure you lock all connections before handing your nibs off to translation. For information on how to lock down your nib file, see “Localization” in Interface Builder User Guide.
Can you explain me this concept? I've seen the Localization Locking section within the inspector which allows you to lock Properties, Localizable Properties or Un-localizable Properties, but I don't understand very well what it does.
So, to sum up a bit, I'd like you to suggest me what is the workflow to design localized versions of your interface and maintain the multiple NIB files when the interface evolves.
EDIT: any idea and/or link that can help me?
iLocalize provides an easy way of localising an app and updating translated nibs. If you'd rather use ibtool, --localize-incremental, which will handle the changes in a nib and copy them to the translated nibs, is explained well here.
Alternatively, you could use NSLocalizedStrings and one nib which is useful in some instances. Set each control's title in code and you need only worry about making the controls wide enough for the longest translation.

Resources