I am creating a swift framework which has some reusable UI components.
When I am importing this framework in another application, I am able to add custom component programmatically.
But, if I add UIView on storyboard and change its class to customComponent, I am not able to see its preview on storyboard. Due to this i cannot distribute this framework to other developers as they can't visualize the component in InterfaceBuilder.
Though, I can see the component at run-time, it reduces the effectiveness of using framework in storyboard.
I have followed a link to develop swift framework.
Thre are two projects Library and SampleApp.
Libray : This is a swift framework which as one custom ui component as MyButton. its very basic ui just to avoid any confusion.
SampleApp : This application uses Library to show MyButton on sample screen
Please let me know the way i can see the preview of custom UI component from framework in any other application.
Edit1:
I have uploaded my sample code where I have applied the suggestions, but not able to resolve this.
Code
Edit 2:
Rectified the broken link of tutorial. I have not used outlets just to make it simpler.
Edit 3:
There are two projects: Library and SampleApp
I have MyButton.swift as a custom widget in Library project.
I have added UIView in StoryBoard and changed its class to MyButton(from library Framework)
Certainly there is!
After you import your framework:
import MyFramework
In IB, select the framework module:
EDIT:
Of course, I'm assuming you've made the custom components IBDesignable.
EDIT #2:
There should be no need to "import" into your storyboard. All you want to do is make sure that your view controller code has the import in it and that your storyboard's view controller is that subclass. For instance, here's a view controller named MainViewController:
And to set your view to be controlled by it:
Related
When using Cocoapods most installation guides instruct to install via Terminal (which is easy)
and then in Xcode to create a new ViewController inheriting from a certain file (which was installed via Cocoapods).
How do I do this?
Obviously creating a new file is fairly easy, but I don't understand how to inherit from another file?
Thanks
What you have to do after importing the custom class is to SubClass your view controller.
You do this in Interface Builder by selecting the VC, going to Identity Inspector (Right panel) and selecting your SubClass in the Custom Class section, as depicted in the image below:
I have integrated EDStarRating in my application. it is working fine on one viewcontroller. but strange problem is it is not working on another view controller.
I have searched almost all google quection releted to this problem but nothing is working for me.
I have deleted EDStarRating from my application added again. then also it is not showing in custom class drop down list. I have checked in build phases, it is there.
Another strange thing is it is not showing in custom class drop down but it is working fine on one view controller there is no issue.
same thing trying to apply on another view controller it is giving error.
Unknown class _MyApplication14MYEDStarRating in Interface Builder file.
Appreciate for help
Are you writing both the view controller that it works on and the one it doesn't in Swift? That you're getting a module-mangled class name for an Objective-C class suggests that you're running into a form of this bug:
Objective-C class is interpreted as Swift class in Interface Builder
Actual Results:
Outlet will refer to a Swift class - Name is mangled with App module name, so it can't resolve to an instance of that class.
The result is the subview having the original class in interface builder. If it was dragged from a 'View', it will be an instance of UIView, if it was dragged from 'ImageView', it will be an instance of UIImageView.
What I'd suggest is taking a look at the source of your storyboard (right click, Open As > Source Code) and manually copying the customClass from the instance that works to the instance that doesn't. Assuming they are different, and Interface Builder just got confused. If they're not different ... then there's some more subtle Swift/Objective-C bridging problem. Probably just rewriting EDStarRating in Swift would be quicker than figuring it out, really.
I have an objective-c project. I want to create a single swift file in the project and use it to initialize and present a view controller which has been assigned the swift file. Note that i do not want to import a whole swift project. Just a single swift file.
I have added #import "MySwift-Swift.h" and anything else i could find in the web but non of them works.
To create the file, right click on your project name and click 'New File'. Then make sure you're in the iOS section, at which point scroll through the categories (I believe you can find it in 'Source') and click 'Swift File'.
Name it whatever you would like and make sure that it's a subclass of UIViewController. Then in your storyboard, in the inspector, change the class to what you named your file.
Hope this helps,
Will
I've got a class and xib that are fairly generic. The xib has a base UI that I've included in a framework. Is it possible for me to add the framework to a project, and create a custom xib to customize my framework xib based on the new project UI needs?
|------------------------|
| MyFrameworkClass | MyCustomXib
| MyFrameworkXib |
|------------------------|
In MyCustomXib i've set the custom class of the files owner to MyFrameworkClass. I notice that I can wire up all my IBOutlets by right clicking on file's owner and dragging to the subviews to make the connections, however I cannot click on the view and drag to file's owner. Also When I go into split view mode I'm not seeing MyFrameworkClass as the code side of the split view?
Right now i'm trying to initialize it with:
MyFrameworkClass *mfc = [MyFrameworkClass alloc] initWithNibName:#"MyCustomXib" bundle:nil];
I'm confused because I'm seeing labels that are created dynamically in MyFramework class showing up in the custom UI, also newly modified button images are replacing old ones, however the buttons are not responding to touches, and the xib resizing is not working correctly.
Edit:
I just went through and compared the xib in the framework and my custom one and found that I could connect all my Outlets to the proper UI elements, however I could not connect any received actions using interface builder. By that I mean when I ctrl+click on a button and drag the connector up to File's Owner, I do not get the glow around File's Owner or a prompt to connect to any methods.
Yes. As long as the class is loaded into the runtime when the XIB file is read, it will work perfectly fine.
It will work. :-) Post additional details of what you mean by "framework" if it doesn't.
I am trying to implement the OBShapedButton class in my iOS project so I can create irregular shaped buttons defined by png files. This is a link for more information on OBShapedButton.
Basically this class works great when I'm using it with my nib files. However I prefer using storyboard in my projects. But when I try to do the same thing in storyboard, following all the same steps for making an irregular button as I do in my nib files, it doesn't work and the clickable area is still defined by a rectangle and not my png image.
My question is how would I go about using storyboard with OBShapedButton? Is there something I am missing about storyboard that would prevent OBShapedButton from working?
I'm using it in a project with Storyboards. Be sure the set the Custom Class in the Identity inspector to OBShapedButton, I don't think I did anything else special.