UPDATE: Edited for clarity.
This is not a showstopper, but it is annoying, and I'd like to figure out how to address it.
I have a custom UIView. A UIScrollView, to be precise, that is programmatically populated with a bunch of UIViews at runtime. It is not meant to have anything embedded in Interface Builder (IB).
What happens with any UIView, is that when you drag another element over it, the UIView becomes "droppable," and allows the other element to be dropped into it.
There are a few native Apple elements that won't let you drop stuff into them, like UIPickerView.
Is there a flag or something I can set, so that it won't allow IB to add anything to it?
Like I said, not a showstopper. If stuff gets added, it is destroyed before the programmatic population happens, but it just seems "neater" to make it clear that it's not "droppable."
UPDATE: In the screengrabs below, the Login Picker View is a standard UIPickerView, and the Display Results Scroller View is my custom scroller. If I drag something out of the Library, and try to drop it on the Picker View, nothing happens. However, I am able to drop it into my Display Results View.
What I want, is to be able to declare my Display Results View as a "no fly zone," so it is no longer droppable.
I hope that makes it clear.
Cannot Drop onto A PickerView
Can Drop On My Custom View
I'm not saying this is a great solution, but if you're using a storyboard (not a xib) then it seems to work…
In your storyboard, instead of dragging a scroll view out of the library, drag out a container view.
IB automatically creates a new storyboard scene connected to the new container view by an embed segue. Delete the newly-created scene.
Set the container view's custom class to UIScrollView.
IB does not allow you to add any subviews to a container view.
Note that IB also doesn't show you any UIScrollView-specific properties in the Attributes inspector, so if you need to customize this funky scroll view, you have to do it programmatically.
The library doesn't offer the container view in a xib, hence the storyboard requirement.
Related
I was googling for a while and I found similar problems but when the custom View is inside a ScrollView, but that is not my case.
I have a custom view that consists of a UILabel behind a UITextField, so I can animate that label later.
The problem is that when I add a View in my ViewController and in the Identity Inspector I set the Class as my custom class, when I use the application the UITextField within my custom view does not receive the touches well and it takes time to gain focus and therefore to open the keyboard. The strange thing is that if I move that same arrangement of views to my main ViewController in Storyboard everything works fine. Why doesn't it do it when I place it using the described method?
I plans to reuse this custom view a lot, so putting logic and views in each ViewController is not an option.
Thanks in advance
Well, the problem was in the constraints of the container UIView. That means, the UIView in my main ViewController. The Height of the UIView was a little bit smaller than the space required for my custom view, so although my custom view seemed to draw correctly, it was not receiving the gestures correctly. The solution was simply increase the height to the correct value occupied by my custom View. Thanks a lot!
I want to make the horizontal swipeable page like YouTube. Is there an object in XCode for this? How do I have to do it? I did not find a tutorial about it. Sorry for my English.
Like this
There are tons of components already made for this in the internet, you can try looking at the cocoacontrols site.
If you still want to write your own code for this, one way is writing a custom UIView subclass. The YouTube feature looks very simple and as far as I can guess, they can use two separate UIView subclasses: one for the menu and one for the pages, just as a container.
For the menu you can use UIStackViews or a single UIViews with UIButtons for the page's titles and another view for the selection effect that moves with the UIButton's touch event. This view should provide a delegate or any notification system that fits better to you in order to notify the container that needs to load the right UIViewController's view inside the container.
The container can be a UIView that loads the view property from the UIViewController subclass on demand. Make sure to add the loaded view controller as a child of the parent view controller, otherwise you will loose some important features.
I hope it can help you to start.
Is it possible to resize and rearrange UI components (say segmented controls, buttons, labels, etc) when these are created using IB?
I need to rearrange/resize few UI components on a button click on iPad screen.
Any idea?
It is possible.
You will need to create IBOutlets for the UI components you are interested in, then you can adjust the properties you are interested in (UIView's frame property)
IBOutlet's are created in the *.h file for you View controller.
IBOutlet UIView * view;
Then you can control click and drag from the file owner (in xib) to the UI element. (or right click and drag)
Yes it is. Implement the viewDidLoad method in your controller and set the frame to whatever you wish for your views and controls so long as you've attached them to an outlet.
Example:
self.myCustomView.frame = CGRectMake(x,y,width,height);
You may also access them by their tag.
If you assign them unique tag numbers in IB, then in your code, you can search within subviews of your view and find them by viewWithTag method.
You can set the initial position of the components in IB, hook up the elements with IBOutlets and on the button click move them in code. I don't think you can rearrange them in IB.
For a cool effect you can use [UIView animateWithDuration:animations:] to move whatever components you need
I have some xibs with all sorts of text controls (UITextFields, UITextViews). Since the keyboard obscures some of these text controls when text input starts, I followed Apple's guideline for managing content located under the keyboard.
In short, the solution involves moving all interface elements on a UIScrollView. Doing it from Interface Builder I simply add a UIScrollView on the view, make it the size of the view, send it to back and link it's referencing outlet to the file's owner view property.
In IB this all looks fine, and the UI elements appear above the UIScrollView. However when I run the program, the UI elements are nowhere to be found. Their IBOutlets however seem to get initialized so it looks like they are actually constructed. I've tried to set the UIScrollView alpha to 0 to see if they are placed behind it but I still can't find them. New items that are added to the UIScrollView however, seem to work fine.
This leaves me with the not so great option of rebuilding all my xibs where I need to do this change. It kind of looks like an Interface Builder bug to me. What do you guys think?
Well I've found a solution. It goes like this:
Drag a UISCrollView in IB's main window (where we have the File's Owner and First Responder objects).
Rescale it to the size of the initial view
Drag and drop everything from the original view to the scroll view.
Link the scroll view's referencing outlet to the file's owner view property.
Delete the old view from IB's main window.
#MihaiD
use tableview.contentOffset=CGPointMake(x,y);
I don't know if you really need a UIScrollView. See this question on SO it slides the parent view up.
I can place a UIActivityIndicatorView on a UIWindow or a UIView by using Interface Builder like as follows.
(source: hatena.ne.jp)
But I can't place a UIActivityIndicatorView on a UITableView by using Interface Builder.
What's the reason? Are there any ways?
I can place it on a UITableView programmatically.
(source: hatena.ne.jp)
Make the UITableView and the UIActivityIndicatorView both subviews of a parent UIView. You can then place the indicator view atop the table view.
The reason is because UITableView expects to be in charge of all of every one of its subviews for layout purposes. IB doesn't let you put subviews in a UITableView because while it is technically possible it is not supported.
In any case, the activity indicator would scroll up and down with the table, so even if you add it at the right place if the table is scrolled down, you could scroll it off the screen if you're not careful about deactivating user interaction while the indicator is showing.
When I need to show a generic activity indicator on the screen over everything, I use my own version of the UIProgressHUD. The UIProgressHUD is a private internal class, so I don't use that, I just made my own that does the same thing. It makes a view with a black background at 50% opacity and rounded corners, and I add a progress indicator and optionally a label to it, then I just add that view to the main window. Thus, no need for another UIView to encapsulate both, and you're not putting it in the table, which isn't supported (unless you put it within a cell within the table view).