i'm writing a small app to train myself and i need a little help.
can anyone give me an advice how to make this construction like on the picture bellow?
i'm interested about "Description" section. i want to make the similar thing in my app. some text in preview..button "more" and when i click it the whole text will appear on the screen. also i want to have the same button "hide" that returned me to the preview.
i need UITextView or smth else?
rmaddy is right, UILabel is the way to go.
You need to hide the More button, and show a Hide (or Less?) button and the label when the user taps. You also need to change the row's height to accomodate for the new content.
To find the appropriate height for the table's row, use either [UILabel sizeToFit] or [UILabel sizeThatFits].
To animate the height change of the row, have a look at Can you animate a height change on a UITableViewCell when selected?
Related
I need to horizontally center layout a UITextField, however, since the clear button is part of it, the (text entry portion of) text field doesn't look centered - the clear button isn't always visible but it is taken into account when laying out.
In the image above, the UITextField is horizontally centered, however, without the clear button (X on the right) and with only search text, it doesn't look like centered.
A way I can think of, is to subclass UITextField and provide alignmentRectInsets, for inset on the right I would use clearButtonRect(forBounds:) to get the size of clear button, whose width will be the right inset for alignmentRectInsets.
Question:
Apple's doc specifically mentions that one should not call clearButtonRect(forBounds:) directly, so I'm feeling a bit nervous for doing it; However, from the doc it feels like Apple's intention is to let people not changing the rect, and in my case I'm just getting its size, I guess it's fine?
Is there any better way of achieving this? I know I can tweak edgeInsets, or give the text field a leftView, to make the text field looking centered; But they all need some hardcoded assumption for the size of the clear button.
Thanks!
You can make the UITextField Alignment settings as middle then it will work. Check the below image
You can control over here.It may helps to you.Thank you.
I've a collection view that has on its header some views as user inputs.
In one of them I've something like a Biography textField, but when I'm typing the text continues all the way to the left, and what I'm trying to achieve is that when the text reaches the visible end, it goes to a new like and so it increases its own height.
How can I achieve this?
I want the Bio text field to increase its height based on its text and not stay the same height and the text goes all the way long to the left.
Regards ;)
UITextField is one-line only element. You can try UITextView instead
EDITED
I've never done this, but this thread seems to do something like dynamic size with UITextView
I have a simple table view which looks like this
Each button overflows some part to next cell (part of requirement).
I want that overflowing button's click event. How to get that ?
By default its taking it as cell click rather than button click if i click on that overflowing part.
I have created a dummy code which changes button color on click, so it is easy for someone to try it out. same layout.
Thanks
EDIT
Below is the original image , what i am trying to do , for simplicity sake i scaled it down to a button
Lets assume req is u cant change height and cant play around table view separator
You have to implement 'tableView:heightForRowAtIndexpath:` method and return greater value than it has now. Your cells don't have enough height to display buttons fully, and because of that some part of your button hides behind of next cell. You can be convinced easily by checking "Clip subviews" checkbox of your Cell Prototype in the interface builder, and if you will see that buttons will be clipped.
EDIT
Check this: https://github.com/arturdev/test
Subclass UITableView and override hitTest:withEvent: and figure out if point is within the frame of one of the buttons. Return the button if the point is within the frame or just return [super hitTest:point withEvent:event] otherwise.
You can use CGRectContainsPoint and [UIView convertRect/Point:to/fromView:] to make calculation easier.
hitTest:withEvent: is a way for the system to ask the outermost view who will receive the event at a given location.
Make UITableView seperator to None. draw 1 or 2 pixel height label with black background color in cell.
Make cell selection style none in cellForRowAtIndex.
cell.selectionStyle = UITableViewCellSelectionStyle.None
Manage proper autolayout or autoresizing mask.
Just tried with your code.
Download from link
Image
I have a UITextField that will represent an integer number with a fraction (numerator and denominator). As an example: "27 3/16". I want to make the denominator "/16" at the end both un-editable and also un-selectable.
I can use the delegate method textField:shouldChangeCharactersInRange:replacementString: to prevent the "/16?" from being edited with an approach a bit like this.
Is there some way that I can also prevent the "/16" from being selectable at all? So, the caret can't be moved in to it, and the selection marque can't be made around it.
If this isn't possible, is there a hook so that once the user finishes placing their selection, I can update the selection and move the caret to just before this piece of the text.
Thanks.
You can have a UILabel and UITextField constrained via autolayout next to each other, the UILabel containing the denumerator and the UITextField the numerator.
Here is an answered question for how to do that: Using Auto Layout to have UILabel and UITextField next to each other (the essence is, you need to adjust the content hugging priority of the UITextField to make it always as wide as the contained text.
If your text field gets too small to be tapped, you can apply the code of this answer to a UITextView and make the tappable area of your view bigger: UIButton: Making the hit area larger than the default hit area (but better use method swizzling than overriding a method in a category like in the answer! Or a subclass.)
How can I add a button in textview? for example..
textView.text=#"text here\n\n text also here\n\n text here aswell";
How can I add a button after each "\n\n" or along the text?
You can create a object of UIButton and add it as subview to yout textview.
You need to preset the frame of the button So the text must be statis and you must know the position of the button in advance.
so your \n\n creates a paragraphs
You can do it without static text just split your text in separate textviews by \n\n, add them to your scrollview. You have to measure your text paragraphs height to set the right frame for textviews and leave gaps for buttons. I would rather use tableview so you dont have to worry about that. Add buttons in between, it is doable.
you may reconsider adding buttons along the text this way (you can but it is really convoluted way of doing things), use webview for that as already stated here by others