Custom UIView in Xamarin Storyboard - uiview

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.

Related

Is it a good idea to use xib files in storyboard

I have a project which is based on storyboard. The problem is some views are repeated in some view controllers.
I created xib file for these repeated views and then I use don't create theses view again. I just add a uiview and set its class to the custom view I have created.
It work ok as it avoids repeated view changes.
But I don't know if this cause performance or any other problems later.
And I cannot change the whole project to only use with xib files.
one of the clean code goals is to reuse your code. so base on this, xib file is a good solution, but about performance, using interface builder has less performance than implementation through code. if you are concern too much about performance, use the code, if not, your implementation is ok.
If your project has similar kind of design or view then yes using xib with storyboard is good. you can reduce redundancy by taking similar kind of view or Tableview cell or collectionview cell. that will also make your storyboard neat and clean.
you can check this and based on that you can use as per your requirement.
Which is more efficient way? StoryBoard or XIB?

Storyboard of a mockup

I am working on an e-commerce based app, and the designer has passed on the mockup to me. !
This is the mockup the designer has passed.
I am working on storyboard of this mockup and I have managed to get to this level as of now.
There are several views and features which cannot be included in this storyboard now because of the limited space. I know the designer has passed on me the rendered view, which can be seen on scrolling the app.
I wonder which could be the best approach to include all these views in a single storyboard or render them in a single view.
I have looked onto using xib files and calling them from my viewcontroller class, which could be a possible solution. But, I want to know, what could be the best solution?
Best solution is use Storyboard so that you have all screens at one place. But keep one thing in mind that start doing the whole project in XCODE 8 storyboard (Because XCODE 7 and 8 storyboards are not fully compatible with each other). So that you get compatibility with previous iOS versions also (< iOS 10)
Now as far as design is concerned, I would like to suggest you use autolayouts and proportional layout.
your View controller will always have self.view. Start on that view. First add navigation controller (with root view controller as your first prefered view controller on app start) or simply add one toolbar. Then add one UIScrollView to whole remaining space. Then start with your design inside UIScrollView. Don't forget to provide contentSize of UIScrollView.
For any help, feel free to ask.
The best solution would be using a tableView with multiple prototype cells for this kind of problem. Well, going through the concept as mentioned, I could easily scroll in the storyboard and maintain my design as per the mockup.

iOS multiple XIB in a View Controller

I have a View Controller that displays 3 custom views. My question is, would it be better to create a XIB for each subview or not?
I have been told that loading a XIB file is really expensive, so it's better to have just one XIB for the View Controller and avoid having XIB for the custom views in that controller. However, in order to avoid that, I have seen the custom views' constraints set by code (as there is no XIB for them and no way to use the IB), which I don't like. That's why I'm wondering if it's fine (both a good practice and efficient) to create a XIB for each subview and set then set the constraints using the IB.
Thanks in advance.
Unless you are planning on destroying views with a large amount of components and rebuilding them serval times a second you should not notice any performance hit. If you do, cache them.
As for best practice (in my option) you don't use XIBs for the efficiency, you mainly use them because they are quicker to build and easier to understand if you need to revisit the view at a later date.
If your going to use AutoLayout in code anyway I would use XIBs where possible as you get the advantages above. The layout engine is usually the expensive part anyway.
Hope this helps.

How do I use both xibs and storyboard in my program?

I've made a project based completely on xibs. Now I need to add a table view whose cells will lead into the xibs I have in my project. All of the tutorials I've found for table view use storyboard, so I was wondering, how I would go about building the table view in storyboard in my current project and then having the detail view be my xibs? If that's not possible, would I have to start a new project that uses storyboard and then add all my xibs into the project? Finally, I think the easiest solution is to make a table view using xibs, not storyboard. Is this possible and if so, how do I do it?
Please let me know if my question is unclear or if you need my information. The last question I posted was left unanswered because I didn't ask correctly and I still have no idea why...so I don't want that to happen again.
The help is much appreciated. Thanks
You can add storyboards into a mainly xib based project but as you said using UITableView with xibs is what you would prefer and yes, you can do this.
If you go to File > New File > Objective-C Class > subclass UITableViewController. Tell it to make you a xib. This will implement UITableViewDelegate and UITableViewDataSource for you. Then you just need to provide it the necessary methods and it should work from there.
Here is a good tutorial that may help you: http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/ (some of this is not relevant if you subclass UITableViewController because it will automatically establish the Delegate and DataSource properties).
Also, feel free to ask any questions if something does not make sense. I am a bit unsure as to what you are after exactly so my answer may not be perfect.

How to create custom reusable UIControls in XCode 4.1

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).

Resources