Create iOS 7 UIButton With Text And Image Using Autolayout - ios7

Using Autolayout and Interface Builder with the target device being iOS 7 iPhones, how do I create three of these kind of UIButtons that have an image, a divider line and text? The 3 images for each of the buttons all have the same size. The lines and text in one button must line up with the other buttons' line and text (left align the text). Things can't go crazy if the phone is turned to landscape. All buttons are the same constant size.
The buttons are part of a home screen layout which has a logo at the top and so on. When one taps one of the buttons, the app does something.
One thought was to create a button with no text, put a label on top, a thin view for the line on top, and the uiimageview on top. Maybe explicit layout constraints are not even needed? Maybe a containing view is needed for the "button" contents to keep the "button" pieces together?

Image+text can be achieved using UIButton only without adding any autolayout constraints. You set both image and text using -setImage:forState and -setTitle:forState:, and then adjust button insets using *Insets properties. To set the insets properly, play with this great test project: https://github.com/jrturton/ButtonInsets (it's not quite clear from the docs how to use them simultaneously, and this test app should give you the idea).
As for the separator, I'd recommend adding it directly to your images.
But if you don't want to stick to the UIButton and its insets, you can subclass UIView, add 2 UIImageViews (the actual image and the separator), a UILabel, and throw in a couple of constraints. To make the view clickable, you attach a UITapGestureRecognizer to it.

Related

uibutton on top of image view not aligning

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

Xcode UITextView Still not scrolling using storyboard

I am trying to initiate a scroll view in my UITextView and even though I seem to have selected the appropriate boxes, I can't seem to get the scrolling working. I have gone through multiple questions similar to this but none seem to have the answer.
I included an image of Xcode below:
Question 2: When I scroll down the majority of my text shows but the scrolling stops with two sentences or so left and I have to scroll down and hold it there to read. Any way I can fix this so it scrolls all the way to the bottom of the text?
Can you check the two boxes: Bounce Horizontally and Bounce Vertically and see what's happening? Sometimes your content are actually way bigger than your view, and they are touching a invisible outer box. If you can see they actually move, that means there is nothing wrong with touch or scroll, is just the view layout problem.
For the content issue, my guess is that the content size is not right, you can programmatically adjust it with textView.frame property, set it to a proper size, such as the frame of the window or the frame of the content, which are CGRect classes. Comment below to see if this can solve your second problem.
The text view will not scroll in storyboard, only the app. And the text view will scroll once the content in the text view exceeds the frame size.
If you're using iOS 7+, you can just turn on auto layout, pin each of the sides of the text view to the edge of its parent view, and it works fine without needing to do anything in code.

Making a CustomView with a static vertical size in Cocoa

I'm making a document viewer in Objective-C, I want to have a bar at the top of the page with a bunch of buttons in it which open up menus, change pages, etc. At the moment I'm using a custom view which then just has all of the buttons inside it, but my problem is that it isn't a static vertical height, so when the window resizes it changes the size of the custom view rather than my PDFView. Is there a way I can stop it from resizing, or is there a better method I should be using to create a menu?
Thanks!
With auto layout, you can just give the view a fixed height -- from the editor menu, choose Pin, then Height. Make sure that it then only has one vertical constraint, either to the top, bottom, or centerY.
Are you using Auto-layout ? You may have to play with it.
Without seeing the code it's hard to debug the problem. Post the snippet where you're re-sizing the views if you're not using auto-layout.

How to put background for UITableViewController

I wanna do something like THIS in my ipad application, what is the best way to do the followings:
The shadow under the upper bar.
The padding for the papers (top, left, right & bottom)
The background (as a notepad) : please think about the cells: they must still scrolled inside the paper and cropped before reaching to the paper bottom edge.
I'm looking for the optimal solution that avoids overriding as much as possible.
EDIT :
I tried to use UIViewController (with UITableVIew and has the delegate methods) inside UISplitViewController, And I tried adding UIImageView at the top of the table but this view will scroll with the cells and it'll hide when I scroll down. I tried to use viewForHeaderInSection function also for upper shadow (under the bar) but what about the papers bottom edge (what if I put one image including the shadow and the papers bottom edge and has the padding as a background for the UITableView or UITableViewController, and change this image when rotate to the portrait orientation? is this a good and possible solution?)
My guess:
Create the background in an image editing app
Cut 4 images, for header, footer, left and right sides
Create a UIViewController with 4 UIVIews and add the correct images as background
In the middle of all 4 add a UITableView
This way the images won't move and if you position the UIViews with the background properly, your TableView will scroll inside the notebook (assuming you are trying to create a notebook)
If you app is iOS 6.0 only, autolayout will be a great help. Check apple developer video on it to learn how to use this feature: WWDC 2012 Session 232 - Auto Layout by Example
One easy way to do this is from the xib:
1. In xib create image .On image view you can put background whatever you want as a image.
2. create table view above the image view and set table view background color as a clear color.
This will do it.

How can I add NSTextView and NSMatrix controls in a single scrollable NSScrollView?

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.