Is it possible to extend the interface builder's attribute inspector with additional attributes for custom classes inheriting from UIView?
Not at the moment.
Interface Builder allows you to implement custom inspectors for your objects by means of an Interface Builder Plugin. However, IB Kit doesn't currently support making plugins for iPhone OS. Only plugin development for Mac OS is currently supported.
Related
Is it possible to create a SpriteKit game without the main storyBoard that get created by the interface builder ?
Because I'm using theos to make apps and it doesn't have an interface builder so everything have to be done by code
Yes, it's possible. You will just need to add all the views and sprites, etc in code, but it is possible.
I saw in eclipse articles saying that we can subclass Canvas and Composite.
And they have mentioned some points about subclassing the components.
Is that only applicable to SWT components or are they mentioning general
disadvantages of subclassing all the UI widgets? Please refer the site below.
Writing Your Own Widget
They are saying you should only subclass Canvas and Composite. All other SWT widgets do actually check for subclassing and throw exceptions (although this can be overridden).
As the article says the widgets are generally platform specific so you would have to do an override for each platform. Since the widgets are not designed to be overridden the internal fields and methods are usually not accessible anyway.
I did this wonderful tutorial: Photoshop Tutorial For Developers: Creating a Custom UISlider and came away with two questions:
The example above makes every UISlider customized. Can you just subclass UISlider and tweak this code to make it it's own class that can be called upon?
Further, could you make this custom control available in the object explorer within Interface Builder, so you can just drag and drop it on your view like anything else in UIKit?
The docs for CocoaTouch classes will usually indicate if a class is not designed for sub-classing. In the case of UISlider, there's also some instructions for customizing appearance.
Custom Component in Interface Builder
To use a custom component within Interface Builder, its necessary to use the "object" component, and specify the class type to your custom class. Unfortunately this does not render any visual queues, like core UIKit classes.
Your own Plugin
It may be possible to provide a plugin to tweak Xcode, however this is no small undertaking as there are no official docs, so its necessary to search for open-source plugins on GitHub, etc and study the code. Even then, the plugin may break with subsequent version of Xcode.
Recommended Approach
Interface Builder is an amazing technology, however for more complex applications I recommend implementing views in code (override loadView in the VC). Here's some reasons:
Promotes better encapsulation and reuse. You can compose your own components (eg composition vs inheritance) using UIKit components, and provide a custom OO interface to them. Contrast this with lots of IB outlets in a view controller, which leads to poor reuse.
Fat-controllers don't really honor the MVC paradigm.
More flexible and fluent. Not all properties are exposed via IB, so in a complex case, its hard to know where to look. Is that setting in IB or code? Custom fonts, for example.
Xibs are really tricky to merge in a multi-person team.
Is there a simple way to expose, say, NSString or UIColor properties of a class such that they can be modified in interface builder?
This would be useful e.g. for adding color properties to a custom view (which are then used programmatically) so that they can be manipulated in Interface Builder as is appropriate.
In iOS 8 there are two new properties added, #IBInspectable and #IBDesignable. Here's a full write up.
http://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/
This article from Cocoa with Love describes how to do what you want with Interface Builder Plug-ins for Mac development. Unfortunately, it is currently not possible to use IBPlugins with the iPhone SDK (note the Interface Builder Plug-in Programming Guide only appears in Mac OS X documentation, not iOS documentation).
There is no way to add a custom "non-IBOutlet" attribute but I suggest you to add a UILabel to make use of the text attribute of it, and of cause release that when the view is loaded.
I seem to enjoy designing new UIViews and UIControls that implement their own -drawRect: method. This work well for me, especially when composed using UIViews in Interface Builder.
But composing them in Interface Builder is annoying because they just show up as boring plain rectangles.
It would be great if the views would actually render themselves as the built-in controls do.
Is there any way I can structure my project so that Interface Builder will render my custom views?
In order to do this, you actually have to create a plug-in for Interface Builder that uses your custom class. Once you create and install your plug-in, you will be able to drag and drop instances of your class (your view) onto another window/view/whatever just like any other control. To get started with creating IB Plug-Ins, please see the Interface Builder Plug-In Programming Guide. Also, I recommend taking a look at Aaron Hillegass's book, Cocoa Programming for Mac OS X. As well as being very well written and easy to understand, it has a chapter on creating your own IB Palette controls.
This is achievable by marking your UIView subclass with #IBDesignable. Once you do this, your custom views will render themselves in Interface Builder. You can even add parameters that can be configured by marking them as #IBInspectable. Here's a Swift example:
#IBDesignable class customView: UIView {
#IBInspectable var count: Int = 0
}
There's an article on NSHipster that provides more detail.