I have to display a small portion of a long text in objective C.how we will use TTTAttributedLabel to add a Read More button to display all text.
Thanks in advance
Use attributedTruncationToken to set the ".. Read more" at the end of the label.
Set an attributed string with a link such as NSLinkAttributeName: [NSURL URLWithString:EXTagURL].
Then use the delegate method below to navigate to the URL of the attributed string you set.
-(void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url{}
Hope this helps.
Firstly make sure you have updated cocoapods
In your terminal:-
gem install cocoapods ,
pod install
Then set the label to class TTTAttributed label in your storyboard.
Then create an outlet to your view controller
#property (weak, nonatomic) IBOutlet TTTAttributedLabel *articleDetail;
Then create an attributed string
in viewdidload
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:#"Read More .."];
[attributedString addAttribute: NSLinkAttributeName value: [NSURL URLWithString:#""] range: NSMakeRange(0, attributedString.length)];
self.articleDetail.attributedTruncationToken = attributedString;
Then finally create delegate method
-(void)attributedLabel:(TTTAttributedLabel *)label
didSelectLinkWithURL:(NSURL *)url
{
}
Related
I'm new to the Objective-c language. I'm trying to create an app that has a button and a label. The button should display some text which I did already. The only problem is that when I click the button, it only adds the specified text once. I want it to keep adding the same text to the label each I time I press the button.
Here is my .h file
{
IBOutlet UILabel *label;
}
-(IBAction)btnClcik:(id)sender;
Here is the .m file
-(IBAction)btnClcik:(id)sender
{
label.text=#"test";
}
To append to the existing text, use the string's concatenation method...
label.text = [label.text stringByAppendingString:#"test"];
You need to append to the string?
Then do
label.text = [label.text stringByAppendingFormat:#"%#", textToAdd];
where textToAdd is a NSString or some other valid object where %# is the correct format specifier.
I have an app where the users enters information in a few textfields which are then added to a uitextview by a nsstring does anybody know how i can set one of the textfields to italics and keep the others normal
regards
Edit:
Heres my code i want to only change once textfield (e.g textfbookpublisher):
NSString* combinedString = [NSString stringWithFormat:
#"%#,%#.'%#.'%#.%#,%#.",
textfbookpublisher.text,
textfbookauthor.text,
textfbooktitle.text,
textfbookplace.text,
nameofuni.text,
textfbookyear.text];
DissertationGen*bookg = [[DissertationGen alloc] init];
bookg.message = combinedString;
bookg.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:bookg animated:YES]
A quick search would have given you an easy answer. For example, this post.
Simply set the font of the UITextfield you want to a [UIFont italicSystemFontOfSize:].
try this link see accepted answer and also check TTTAttributedLabel library
Bold one Word
now you want only textfbookpublisher in italic then pass it individually to next DissertationGen view
in DissertationGen controller's viewdidload method use following code
UILabel *lblpubl = [[UILabel alloc] init];
lblpubl.font = [UIFont italicSystemFontOfSize:18.0];
lblpubl.text = your variable which contains textfbookpublisher's text;
now use lblpubl as you wish
How can I change a label's text? This is what I have tried.
labelCheckBox.text = #"This is the new label";
I connected the label in Interface builder for labelCheckBox and created an outlet for it. In the Didload the label's text changed, but in another method inside the class it does not have the new value.
-(void)settext:(NSString*)newLabelText{
labelCheckBox.text = newLabelText;
// labelCheckBox = [[UILabel alloc] init];
// labelCheckBox.text = #"This is the new label";
}
I am calling the method in another class as shown here:
[New settext:#"All Transaction"];
The value of 'NewLabelText' after printing it in NSLog is: " All Transaction ". But when I assign ' LabelCheckBox.Text = NewLabelText ', I print the value of 'LabelCheckBox.Text',
and it gives empty.
First of all if you use IB you need to create outlet and connection for your UILabel. The easiest way it's dragging from your label (control + drag) to your .h file of controller class. Then synthesize it in .m file and now you can change label text as you do this in question.
the 'View' should load before setting the label text.
iOS development sometimes gives you the silence treatment like Javascript to help prevent your app from crashing. With that said, if you have created the UILabel in Interface Builder and have set an IBOutlet for it, make sure you change the text only after the UILabel is created. (i.e. after -viewDidLoad). You can set a break point to where you set the text change and a breakpoint at -viewDidLoad in the UIViewController that contains the UILabel to confirm the order of calls that's taking place.
Below code will change text in label with tag value
In scrollview use this type to change the text in label
for(UIView *views in ScrollViewMain.subviews)
{
UILabel *label = [views viewWithTag:[sender tag]+1000];
label.text=str1;
}
It will really work.
thank you
i have
if(indexPath.row==0)
{
cell.lbl.text=#"abc";
cell.txtField.placeholder=#"abc"
cell.txtField.tag=104;
delegate.copyNameString = [NSString stringWithFormat:#"%#", [cell.txtField text]];
} else if(indexPath.row==1)
{
cell.lbl.text=#"home";
cell.txtField.placeholder=#"xyz";
cell.txtField.tag=105;
}
I am trying to retrieve the text which is in textfield, at row 0 and row 1.
i am trying to retrieve text on the textfield on the basis of tag.
How can i retrieve text?
Thanks
You can retrive your textfield like this and when you got your required textfield ,then get text.
UITableViewCell *myCell = (UITableViewCell *)[*yourTableViewName* cellForRowAtIndexPath:*passindexPath*]];
UITextField *mytextFiled = (UITextField *)[myCell viewWithTag:104];
the direct answer to your question is to use viewWithTag. In your example, [cell viewWithTag:105] will give you the text field. That said, your example has other issues.
First, if you can access the cell and the cell has a txtField property than you don't need the tag. Just use cell.txtField when you have the cell. Tags are typically used when you don't have a property holding a reference to the view you need. If you can't access the cell, the tag won't help you.
Second, you shouldn't add subviews directly to the cell. Instead you should add them to the cells contentView. The docs explain how to create a custom UITableViewCell fairly well.
NSString *textValue=((UITextField *)[self.view viewWithTag:104]).text;
You do like this,
UITextField *urtextFiled = (UITextField *)[self.view viewWithTag:104];
NSString *textValue=[urtextFiled text];
In which method you are trying to retrieve the text? I think you have to set delegate for your textfield and retrieve the text from this delegate method -(BOOL) textFieldShouldReturn:(UITextField *)textField
Hey
Just wondering how do you..
Iv created some code that automatically creates a certain amount of UITextField input by the user.
Each UITextfield has a set tag automatically created.
The user then inputs his value into each of the UITextFields.
I want to retrieve the input text from the UITextFields which correspond to the tag.
I thought I nearly had it with:
NSString * tmpV = (NSString*)[choiceTextField.text viewWithTag:result];
where result is a increment, choiceTextField is the UITextField. With this I get a problem not defining instance, which I can't do as the UITextFields are generated in code not on the xib.
So to sum up, basically want the retrieve the text from a UITextField with specific tag.
Thanks
Dan
UITextField *yourTextField = (UITextField *)[self.view viewWithTag:result];
NSString *getText = myTextField.text;
Hope this helps
Your textfields must be a subview of a parent view. You need to write the following in your view controller of the parent view:
NSString *text = ((UITextField*)[self.view viewWithTag:result]).text;
Just go with Hetal Vora's solution: looks much cleaner!
-viewWithTag can be called on any view and searches all its subviews for one that matches the tag. Thus, you will find your UITextField by calling it on any view that is above it in the hierarchy. For example, you could call it on the view controller's view that contains your text field, as follows:
NSString *tmpV = [[myViewController.view viewWithTag:result] text];
If you are already in the view controller's class you could use:
NSString *tmpV = [[self.view viewWithTag:result] text];
On second thought, the following may be more correct & will avoid any compiler errors:
UITextField *myTextField = (UITextField *)[self.view viewWithTag:result];
NSString *tmpV = myTextField.text;