Hey, I've got a UIScrollView within my main view in the application, and I'm wondering what's the best way to place a set of labels and buttons within it. When I started, there was only a few, so I could physically place them in the interface builder, but now I've got more items to add to the ScrollView and can't fit them all on the screen in the interface builder. Is there a way to generate a sequence of buttons and labels? I just need them in an organized list, but I don't know how to generate content within the scrollview without specifically placing them in the IB, and then give them specific positions.
Alright well what I ended up doing was using the interface builder with the objects visible on screen (Labels, buttons) and coding them as you would when you use the interface builder (i.e. UILabel *label; in the header etc.) and then using the properties in interface builder, set their x/y position, which would move them off the screen, but since they're coded within my scrollview, they take up their spot in the scrollview, and can be scrolled down to.
Related
I have a UIViewController which contains a UIImageView, and I put a UIButton on top of the UIImageView.
I am using size classes (width compact, high regular, all iphones portrait).
When I add constraints to the button, it changes positions on different iPhone screens.
I have checked a lot of size class tutorials, but all of them are like putting button in the centre, or adding multiple buttons then evenly spread out.
Do anyone know any tutorial like adding only one button to the screen, and the button remains at the same position according to the background image?
Settings:
settings
Storyboard at design time
TBC
Remove Use Size Classes and Use AutoLayout and then change the view gaps from the column next to attributes inspector
This way you can have constraints and same location on all devices
My app has an NSToolbar with a horizontal NSSplitView below it. An NSSegmentedControl in the toolbar moves with the splitview's divider, just like the one in OS X's Finder. NSLayoutGuide was used to align the two "views" from different storyboard "scenes". I shared this approach in this related question.
However, I don't know how to move the label with the icon. I've set the minSize and maxSize, but the label is fixed. In the first screenshot below, the "View Mode" label is not right below the segmented control.
It will be easy to add constrains to the label if I can access it. But I haven't found the API in NSToolbarItem, which only has a public view property. I've examine the view's hierarchy (the second screenshot), but I don't think I should use the variables with the _ prefix.
A related but different question is here. That question doesn't take moving into account.
You could try subclassing the NSToolbar setting the title to #"" and then creating your own UILabel and adding it as a subview? then you could reference it's property name and move it wherever you like
I made a prototype for an app, just as a proof of concept to test whether the functionality is working properly or not. Now that I am satisfied with the working functionality, I want to paste the images I placed in a UIView into a UIScrollView, so that I can show data in different pages. But, as I select the elements and paste it in a scrollview, all the positions are lost, and I have to manually place the elements in the interface builder.
Check out this image, I have these many elements that I need to paste inside the UIScrollView.
Is there a better way of doing this? or do I have to manually place the elements in positions I want?
Thanks!
If you want to avoid the headache of repostioning of controls in IB, then try the following option
1) Take one more UIView.
2) Add the UIScrollView into the UIView.
3) Add your current UIView(view which you shown in question) into the UIScrollView.
Thanks.
Select all your children, then Menu/editor/embed in scroll view.
Et voilĂ !
I need to create a scrollable composite view on iOS. That is to say, the view will contain at least one image, possibly a button, and some text (that we may wish to format with bold fonts, etc). The amount of data, and particularly the amount of text, is variable, from maybe 4 lines to maybe 100. The data is "variable" to a degree, and in particular the image and text do not come joined at the hip.
This all needs to fit in a "pane" of about 280h x 115w pixels in a portrait-only layout.
A single UITextView doesn't provide the facilities to display an image or format the text.
A UIWebView provides the ability to display the image and formatted text, but the button is a problem (not even sure if it's doable).
A UIScrollView would easily allow the image and button, and then a UIWebView could be embedded in the scroll view for the text, but then scrolling becomes a problem -- I'd like the entire view to scroll as one, without having to resize the web view to contain it's content, and without the confusion of a scrollable within a scrollable (the doc warns of "unexpected behavior").
(I'm guessing your thoughts at this point are that I want too much.)
So, any suggestions? What's the best way to get close to what I need here?
In iOS5 the UIWebView has a scrollView property, which is a normal UIScrollView. You should be able to add a UIButton as a subview of the scrollView to achieve what you want, although positioning it correctly may be a challenge. Prior to iOS5 you could cycle through the subviews of the UIWebView to find the UIScrollView with isKindOfClass...
I suggest testing with a UIWebView inside your UIScrollView. I don't see any interference in the iOS 5.0 simulator. I don't know if there are problems in iOS 4.0.
If you find that there is interference, you can prevent it by setting the web view's userInteractionEnabled property to NO, either in the nib or in code. This will prevent the web view from receiving any touches, so the user also won't be able to pinch-zoom it, follow links in it, or copy text from it.
In the web view's delegate, implement webViewDidFinishLoad: to set the web view's size and the scroll view's contentSize. For example:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
CGRect frame = self.webView.frame;
frame.size = [self.webView sizeThatFits:CGSizeMake(frame.size.width, HUGE_VALF)];
self.webView.frame = frame;
self.scrollView.contentSize = CGSizeMake(CGRectGetMaxX(frame), CGRectGetMaxY(frame));
}
When I did a similar thing, I had a dozen of views which I added to the UIScrollView and then calculated the frames of all the views. Granted, it was an extremely tedious work, given that some views could get hidden under various conditions. The layout code was actually pretty simple, laying out views from top to bottom, but ugly. The upshot is that it works like a charm, fast and reliably. You can even trivially wrap it in an animation block.
I am new to Mac development.
I want to add three controls in a single Scrollable NSScrollView.
1) NSTextView.
2) NSMatrix.
3) NSTextView.
Please note that text in nstextview can be of dynamic height.... and there should be no scroll for textviews.
here is a screenshot of what I am looking for -
how can I add these three views in nsscrollview? Please help!
Update 1 - can I add these controls in a NSView?
I'll assume you've got a project in Xcode 4 started. Select your project's MainMenu.xib file to begin editing your main user interface.
Start with a window. Drag a custom view into it. Add your text view to the custom view, followed by the matrix, followed by another text view, sizing the views as you go. It's at this point that you also can configure your text views not to display scroll bars. Next, select the custom view. Embed it in a scroll view, and there you are.
The window, custom view, text views, and matrix are selected from Xcode 4's Object Library palette. To embed, choose the Embed/Scroll View command from the Editor menu.
As for the dynamic sizing, you'll have to code for changing the heights of the text views, and so the height of the enclosing custom view. (That is an exercise I leave to you.) Your burden can be lessened somewhat by taking advantage of autosizing to maintain the proper spacing between the three UI elements; you can do this either in Xcode 4, or you can do it using NSView's relevant instance methods.
Good luck to you in your endeavors.