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.
Related
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:
I can't seem even to copy my views from storyboard into an XIB layout, as is the answer to most threads with this title. I think XCode has disabled this feature.
I've looked into manually moving the XML, but it seems that Storyboard uses a completely different (though similar) structure for views.
Is it possible, alternatively, to split up the storyboard files so that they work like XIB files?
Try using the Assistant Editor and having the files open side by side, you can then drag from one to another.
(self answered) I had created an XIB with the OS X setting instead of iOS. Additionally, after figuring this out, I disconnected the storyboard connections and used the layouts with [storyboard instantiateViewControllerWithIdentifier:#"..."].
i'm very new to xcode. i've googled this and even serched here and i didn't find exactly what i was looking for. i really wanna get this. especially since it's the most basic thing there is.
so, i have the .h and .m files
i want to DRAG a uiview into the .xib file, i don't want it to be as big as the screen, so i resize it.
now i want to draw a bunch of rectangles INSIDE this view object.
how do i go about doing this?
your help would be greatly appreciated!
So you add a generic UIView then create a subclass of UIView and do your drawing inside the drawRect method.
Then change the class of the UIView to your subclass name in the inspector.
Be sure to #include your header in the app delegate.
That's the basic thing.
For more sophistication, you're going to want to learn to use UIViewController subclasses as well. These are used all over ios.
Has anyone tried to implement iCarousel with storyboards? I have an existing project, but not sure if this will work with Storyboards or not. Has anyone done this successfully or provide any directions on what do I need to implement this in a Storyboard project?
I've got to admit, I can't work out why Storyboards are causing an issue for so many people using iCarousel, but I've now included a Storyboard example in the project that demonstrates how to set it up correctly.
https://github.com/nicklockwood/iCarousel/tree/master/Examples/Storyboard%20Demo
FWIW, the view controller code for this example is identical to the Basic iOS demo.
Yes, it works with storyboards.
It works exactly the same way as before iOS 5 Storyboards.
You can create a view in your storyboard and set its class property to be "iCarousel".
Then connect iCarousel delegate and dataSource properties to point to your view controller. (don't forget that your view controller must implement iCarouselDataSource and iCarouselDelegate protocols). You can create an outlet for your iCarousel view too.
Thats all for you to access and to control your iCarousel using Storyboards.
Hope it helps,
hbobenicio.
Check that iCarousel.m is in the compile sources list for your app target. Project > App Target > Build Phases > Compile Sources in xCode 4.6.1.
So, another problem is, that if a view-class was changed to iCarousel and command-b is set, after compiling the alert "Unknown class iCarousel in Interface Builder file." comes.
No, no, iCarousel and Storyboard isn't a good idea.
And the solution:
Make a new Class in your Xcode-Project, name it "iCarousel". Via drag & drop put the Code from the original classfiles in there.
After that, it will work'S well.
I found a solution.
Don't copy the class iCarousel in the project-folder by adding them.
Just reference to them. Then it works.
I was having some issues but I just hadn't set the iCarousel.m file's Target Membership to the right thing when I dragged it in.
That is wrong.
I've try to implement iCarousell in a Storyboard-Project and always get delegate and datasource errors. I think it only works with separated xib.
Always: this class is not key value coding-compliant for the key dataSource.'
{Xcode 4.2, deployment target iOS4.3, not storyboard, using ARC}
I started with a tabbed application template & chose the universal platform, which nicely gives me view controller classes & NIB files for an iPhone (ClassName_iPhone.xib) & an iPad (ClassName_iPad.xib) for 2 tabs, with an if statement in the AppDelegate to determine which to run - exactly how I wanted it set up.
I wanted to add a 3rd & 4th tabs, so starting with the 3rd tab (doing 1 at a time) I created a new UIViewController subclass. As it doesn't give the option to create both NIBs at once, I selected "Targeted for iPad", & had intended to create the iPhone NIB manually. I added a "_iPad" suffix to the created NIB file, then I created a user interface view NIB file to which I added the "_iPhone" suffix. I then set up the code for the new view controller in the AppDelegate implementation file to include the 3rd view controller & tab, & I used the other view controller classes as a guide to set up the new class's code.
For the 3rd _iPhone NIB, I dragged a view object from the objects library onto the canvas, & set it up as per the other 2 _iPhone NIBs. But when I went to connect the outlets, there is no view outlet in the referencing outlets of the connections panel to connect with, which I thought there should be. At this point I suspected something was wrong.
I tried running it in the simulator, in iPad mode it works fine (all 3 tabs are clickable). But in iPhone mode clicking the 3rd tab crashes it with a "SIGABRT" on thread 1. It's obvious what I did didn't work. I don't see anything in the output window that gives me any clues.
Being a newbie to obj-c, so not being too sure of the problem, I would have thought that I either:
have used the wrong user interface template (view)
should have used a view controller object from the object library
(not a view)
or that I should have declared some outlets in my view controller
class files.
But if I should have done either of the latter 2, then my question would be why does the iPad NIB work then, when it clearly has a view object in the NIB & no outlets declared in the class files (same with the other 2 view controllers for both devices)?
Does the UITabView class somehow have outlets pre-declared within it for the first 2 tabs? But that still doesn't explain why the _iPad NIB works.
As usual, any help & advice much appreciated, & if there's a link to an explanation somewhere that I've missed, please show me, because I'm happy to do the research.
If what I've done wrong here is not determinable, then I guess ultimately what I'm asking is a clue to how best to create the second NIB file for iPhone to mesh with the class created with iPad NIB.
Sorry to answer my own question but with further searching I found this answer that was the solution, although not quite the whole story. So I thought to put what I did in an asnwer so others can refer to it.
As Piotr Czapla explains in the linked answer, for some reason Xcode doesn't populate the connectionRecords data, as you can see by my first red arrow. Having a look at the view controller that works (where second red arrow is), that's what the data should look like. So the answer is to cut the data & paste it into the NIB file, or type it. You can do this in Xcode by right-clicking the NIB file in the project navigatior & then Open As > Source Code, which is what you see in my screenshots.
The bit I want to add to Piotr Czapla's explanation though is the destination reference pointed to by the second red arrow might not be correct for the NIB file you're pasting into (mine wasn't) & Xcode might not let you go back into IB mode. If so, you need to get the correct reference from the IBUIView class within your NIB file, as pointed to by the third red arrow. Once I copied that reference to my destination reference ref=, as shown by the fourth red arrow, all was ok & the problem was solved. I could then go back into IB mode (right click, Open As > Interface Builder - iOS) & the view works in the simulator.