Create View below dynamic View - ios

I have a label without defined height, her height will be set accordingly to the text that she receives from the array(can be any height).
Now I want to create a webview that goes below the label, if I create it through interface builder the webview will not receive clicks so I thought that i could create programmatically but how can I find the Y(CGRectMake(x,y,w,h)) after the label gets his height to create the frame for that position?
EDIT 1: What i want is to create a View below that label, but what happens is that when the view goes down because of the label she stops to receive clicks
EDIT 2: I Have a label below that is separator(Gray Line to separate) and then a View that programmatically will receive a WebView, but when the Label is short, the UIWebView is clickable, when I have a long label I can't click in the WebView.
The label can have like 50 or 500 as height soo tell me how can I Create a view below that label that will work properly
Thanks in advance

You can use auto layout here..
UILabel *yourlabel = [[UILabel alloc]init];
yourlabel.numberOfLines = 0;
yourlabel.lineBreakMode = NSLineBreakByWordWrapping;
yourlabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[self.view addSubview:infoLabel];
yourlabel -- set leading , trailing and top constrain
below your label you can add your other view.

To add webVIew under UILabel, you need to use insertSubView instead of addSubView.
Try looking into insertSubview:atIndex:
Also look into insertSubview:aboveSubview

Related

Set button in vertical center of table view cell.

I have button and a label in my table view cell placing one after other vertically.
In my xib design i placed my button then below it placed my label.
if the string for label is empty then i want to set the button as vertically center in table view cell and hide the label.
if have tried following code for my implementation but button does not come in vertical center position.
if([labelString isEqualToString:#""]){
_label.hidden = YES;
_button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
}
it would be helpful if get suggestion for fixing this problem.
One approach: use dynamic setting of constraints.
In InterfaceBuilder:
Put your button and label inside an enclosing wrapper view.
Constrain the wrapper view to be centered in the main view.
Constrain the button and the label to be of fixed height, and the top of the label to be constrained to the bottom of the button (with spacing if desired).
Constrain the top of the wrapper to the top of the button.
Constrain the bottom of the wrapper with two separate constraints: one to the bottom of the button (but make this inactive), and one to the bottom of the label (active.).
Make both of those constraints outlets so that you can access them in code.
Leave the wrapper height otherwise unconstrained. Thus it will "shrink-wrap" to the combined height of the button and label.
In code:
When the label is empty, activate the constraint that pins the wrapper to the button instead of to the label:
BOOL hideLabel = [labelString isEqualToString:#""];
_label.hidden = hideLabel;
_wrapperToButtonConstraint.active = hideLabel;
_wrapperToLabelConstraint.active = !hideLabel;
Now the shrink-wrap effect will make the wrapper have the same height as the button, and since the wrapper is centered, so will the button be centered.

make UitextView horizontally scrolling and not truncating the text.

I wish to make a horizontally scrollable uitextview in which a user can type text that is much longer than the width of the textview.
But currently, when i have implement a textfield, the text stops at the end of the textview, even when i continue to type and setting textContainer.maximumnumberoflines = 1.
I wish it to have the same vertical scrolling function where the height textview expands while users types more text onto the textview. But in my case, i want the width of textview to expand to accommodate words.
At the end of the long text, i wish to be able to scroll the textview horizontally to view the full text.
The current failed attempt by me looks like this.
currently, the word stops at "hahahh", no matter how much i type, nothing changes.
textContainer.maximumnumberoflines = 1 ----> This is not required (By default textField has scrolling property). You can initialize textField like this and it works. Here specify your textField frame, superView to which this textField has to be added, color and font.
UITextField *myTextField = [[UITextField alloc] initWithFrame:frame];
myTextField.font = giveFont;
myTextField.textColor = giveColor;
[superview addSubView:myTextField];
You can use TextView instead of TextField.
TextView is located just above the ScrollView in Object Library.
Check this out

TextLabel shifts up when detailTextLabel becomes multiline

i'm currently making an app where the suer selects an MKMapView annotation and then the title of the annotation(pin) is set to a detailtextLabel in a Right Detail UITableViewCell.
My Problem is that when the text is large, the detailTextLabel becomes multiple lines. When this happens the TextLabel of the cell(the one the left) shifts up. Heres What I've tried:
In the cellForRowAtIndexPath Method, I tried adjusting the frame through the following code:
CGRect frame = cell.textLabel.frame;
frame.origin.y = cell.frame.size.height/2;
cell.textLabel.frame = frame;
Where cell is a UITableViewCell that is set to right detail
Subclass the cell and tun try to adjust the frame in the -(void)layoutSubviews
How do I stop it from going up and keep it at the center of the cell?
If you want to do a custom layout of UITableViewCell, then you need to add your custom UI elements to its -[UITableViewCell contentView] instead of trying to modify geometry of standard UI elements that are created by default.
So, in your case, you need to add two UILabels and set their position so that:
Title label will not move at all
Detail text label will be also multiline
In this way you'll be able to solve this problem!
Please try to make the font size adjustable amount to the text.
I think you can use,
cell.detailTextLabel.adjustFontSizeToWidth = Yes;
And also set the numberOfLines to 0.
Hope that solves the purpose.

how to make uitextview none scrollable but display all content

At the moment in my IB I have a View Controller which is covered by a UIScroll View. Within the scroll view I have a UIImageView at the top, a UILableView in the middile and a MKMapView at the bottom. The UILableView number of lines is set to 0 (infinite) and word wrap allowing me display as much content as I want.
I want to be able to tap telephone numbers and website url's for the content in my UILableView. The best way I've found so far is to change it to a UITextView which handles all of this for you. However... I can not get the same behaviour with the scrolling.
Before the image, label and map used to scroll as a block. Now, only the textView scrolls. Any advice appreciated.
the displaying part is correct, that is calculate the frame of the textView based on the size of its text for scrolling add this [textView setScrollEnabled:NO];
You can try using this project:
https://github.com/mattt/TTTAttributedLabel
label.dataDetectorTypes = NSTextCheckingTypeLink; // Automatically detect links when the label text is subsequently changed
label.delegate = self; // Delegate methods are called when the user taps on a link (see `TTTAttributedLabelDelegate` protocol)
label.text = #"Fork me on GitHub! (http://github.com/mattt/TTTAttributedLabel/)"; // Repository URL will be automatically detected and linked
NSRange range = [label.text rangeOfString:#"me"];
[label addLinkToURL:[NSURL URLWithString:#"http://github.com/mattt/"] withRange:range]; // Embedding a custom link in a substring

iOS Center Text on Bottom

I have a label that I create using the following way:
UILabel *label = [[UILabel alloc] initWithFrame:cell.contentView.bounds];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
label.textAlignment = UITextAlignmentCenter;
I would like to center the on the bottom of the label and center it horizontally.
I did not find any UITextAlignmentBottom in the typedef enums.
Can somebody suggest a solution?
To 'align' the text to the bottom, you will want to make the UILabel the height of the text it needs to display - Google UILabel sizeToFit.
I'm not entirely sure what you mean by "center the on the bottom of the label", but I'm thinking you might be asking about how to center a label at the bottom of the view controller that it's in. To do this, you will want to add some NSLayoutConstraints to specify where in the window you want the label to go.
To do this programmatically, you will use constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:. The "attribute" argument refers to NSLayoutAttribute, which can be set as NSLayoutAttributeCenterX when attempting to center the label, and NSLayoutAttributeBottom to specify the amount of space between the label and the bottom of the view controller.

Resources