How to create custom reusable UIControls in XCode 4.1 - ios

I want to create a custom UIProperty Control that is not more than a UILabel and a UITextField grouped together and add it to IB's Custom Objects list to reuse in other Nibs.
I found a lot of documentation and everything points to creating a Xcode or IB plugin project, but everything refers to Xcode 3.x and there are no parallels in many spots.
Anyone cares to help?
Thank you in advance

Unfortunately, it's not easy, if even possible at all. Unlike Xcode 3, in XCode 4, Apple has pretty much eliminated this feature. They now say you must create the class manually first and then associate the controller object using Interface Builder.
InterfaceBuilder Docs explain how to do it now in Xcode 4 using a custom object.
And from the xcode 4 transition guide:
After adding the source file templates to your project, drag a custom view object from the library into the nib file. After adding the custom view to your nib, select the custom view and assign the correct class to it in the class field under Custom Class in the Identity inspector
Some more resources:
iphone-creating-custom-objects-for-interface-builder
Interface Builder Help - Custom Object

Xcode 4 doesn't do plugins.
Creating something that will be customizable in IB doesn't seem to be possible at this point. I think the strategy being used by and large is to avoid IB and do it all in code (e.g. most everything on cocoacontrols.com).

Related

Swift assigning multiple classes to UI element

Is it possible to assign multiple custom classes to the same UI Element in Swift?
I have a UITextField that I need to animate with Spring(Animation library) and I also need to use some other library on the same UITextField that provides some other functionality. I usually assign the custom class in the identity inspector custom class section in the storyboard but I can't find a way to assign multiple classes. I also tried to create a new class and inherit from both of these libraries that I am trying to use but I don't think you can have multiple inheritances in Swift.
You can't, Swift does not support multiple-inheritance. An object can implement multiple protocols but only inherit from one class.
For sorry this is not available in Swift ( Great C++ has it ) , so you have to select anyone and go with it
Ok, I just came up with a great idea that fits my needs perfectly but it might not apply to everyone. Since one of the libraries I was trying to use was purely for animation, I placed my UITextView inside a view, inherited the animation library for the view and inherited the other library for UITextView. Now I have both the animations working and the functionality.

Custom UIView in Xamarin Storyboard

Does anyone know if we can design our custom UIViews in Xamarin's storyboards ? I would like to use autolayout and size classes for a custom View that I need to develop. I am not much comfortable with Xcode, having been so attached to Xamarin's IB. So I would prefer to design it in Xamarin storyboards than going for XIB files. I know we can prototype UITableViewCells in storyboards, but that is not what I want. I want a standalone custom UIView, with a code-behind class that I can re-use.
I am a bit confused as to what you are asking.
Are you wanting to design XIBs in the Xamarin Designer?
Currently, it is not possible as storyboard's XML and XIB's XML are completely different. But it looks like Xamarin is thinking about supporting it as it is on UserVoice here. So you could vote for it and hope it gets added in.
Another option is to start using Xcode.
I have found out a way. But it is kind of a hack and will increase bundle size and thus a memory-inefficient way. First add a View Controller to the storyboard and give a class name to create a code behind, say "DummyViewController". Then drag a UIView to DummyViewController and in "properties" pane give "class" name as the name of the Custom View as shown in the image.
A code behind for this View will be created in project folder, MyCustomView inheriting from UIView. Now we can design the view from within XS storyboard with AutoLayout and Size Classes without a separate XIB file.
I do not recommend this unless you really want it to be done this way. Hope Xamarin will come up with a solution to design Custom Views from within XS soon.

Alternative to creating "connection" between elements in .xib and swift classes via drag & drop

I am currently trying to learn the creation of views with the interface builder and the new swift language.
I want to create a custom Table Cell.
After "designing" it in the interface builder I attached a class to it. The cell has 3 labels. The next step would be "connect" the labels to the code. I am used to do this by creating an IBOutlet by ctrl-dragging the elements in the interfacebuilder to the code.
However due to xcode beta fun this makes xcode crash - every single time. Is there any other way to do it?
Thanks!

Moving view from project created without storyboards to project with storyboards

I've searched for the answer to this but I am unable to find one
(or unable to understand the answers as I'm new to iOS)
I have a project created with storyboards. I would like to add
a particular view from a completely different project (that only uses code)
to my project and be able to alter it with the interface builder.
Is this possible?
Specifically, I am trying to add a tapku calendar to my project.
Maybe there is a workaround if the above is not an option.
Looking in the example Tapku, specifically the section on the monthly calendar, as you can see, you have to create a class that inherits from TKCalendarMonthTableViewController. Copy the example.
To add it to your storyboard, add a UIViewController, and you assign the class you just created.
This you can show UIViewController within another UIViewController by ConainerView, which I think is what you want

Are xibs considered out of date?

Now that Apple has released storyboarding, are xibs deprecated? I've found some of my old tricks (i.e. connecting other views in ib) to not work anymore. But yet at the same time it's nice to have all my views in one file. Thoughts?
Deprecated? Not yet.
Outdated? Yes. Since iOS 5, many new Interface Builder features (like static table view cells and unwind segues) are only for storyboards and not xibs.
Apple also recommends using storyboards in their own documentation:
View Controller Programming Guide for iOS:
In short, creating a user interface means instantiating and configuring many objects and establishing the relationships between them, which can be time consuming and error prone.
Instead, use Interface Builder to create storyboards.
Table View Programming Guide for iOS:
The easiest and recommended way to create and manage a table view is to use a custom UITableViewController object in a storyboard.

Resources