I have some source codes to display all file names in a UITablView
I noticed that if the file name too long, for example filenameabcdefghklmn.dat it will display filenameabcde...
I hope to know what is the best way to display long file name in UITablView?
Thanks
interdev
You can set the label properties of the label in which you are entering text like:
[lbl setNumberOfLines:0];
[lbl setLineBreakMode:UILineBreakModeCharacterWrap];
Now this will show the file name in the next line if the file name did not fit in one line.
You need to adjust the label height also.
Hope this helps,
Thanks,
Madhup
Customise your table cell and draw the string directly to the table cell's view.
You can use sizeWithFont:constrainedToSize: to figure out how big your string will be so you can size your cell appropriately.
This post may help you out:
http://www.ubergeek.tv/article.php?pid=143
Allow rotation to landscape mode. Or use a smaller font. Or just let the label get abbreviated with the "..." ellipsis.
There isn't a heck of a lot you can do here.
Show long name in two line in same row...
like
if([myString length] > MAX)
{
myString1 = [myString substringToIndex:MAX];
cell.textLabel.text = myString1;
mystring2 = [myString substringFromIndex:MAX];
cell.detailTextLabel.text = mystring2;
}
You can use
cell.textLabel.numberOfLines=3;
cell.textLabel.lineBreakMode=UILineBreakModeWordWrap;
Put this code in your cellForRowAtIndexPath tableview delegate methods.
Related
Hello I want the create the Keypad as shown in picture. I have added buttons but don't know how to customize the UIButton as shown below in following link.
http://i.stack.imgur.com/Wt4uu.png
Any suggestion will be highly appreciated .....
We can set attributed string for button titleLabel.
NSString *string = #" 6\n MNO";
NSMutableAttributedString *attribString = [[NSMutableAttributedString alloc]initWithString:string];
//specify proper font for letters on button.
[attribString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:8] range:NSMakeRange(attribString.length -3, 3)];
//similarly add attribute for number also if needed.
self.attribButton.titleLabel.numberOfLines = 2;
[self.attribButton setAttributedTitle:attribString forState:UIControlStateNormal];
#Christeena John, Thanks for quick reply,
The UI looks like this.
http://i.stack.imgur.com/Mvq4k.png
I have used this code snippet from the github :-
https://github.com/kosyloa/PinPad
and updated UI a little bit as per my requirement.
I have a UILabel set its text.But when I check for some condition and try to
change the text of UILabel if condition not met then Im getting the other other text on already present text of UILabel i.e both texts are overlapping..First I want to clear the present text and reset same UILabel to other text ..How can i do it ?
Im doing this
label.text=#"Welcome";
if(check for some condition)
{
label.text=#"Sorry";
}
But both texts are overlapping on each other...Where Im going wrong?
If you want to clear label first
label.text = #"";
and then give some value to the label
label.text = #"Sorry";
I know it's silly but sometimes it works.
Thanks.
I was having the same problem with Swift 3. It was some intermittent that at times and a text exchange look like a label. I have decided as follows:
self.label.text = "00:00:00"
self.label.setNeedsLayout()
You can try this:
label.text = nil;
And after the condition, you reassign the text.
I've 5 labels and 2 text fields in my iphone application when i end the application and restarts it the label and text fields will contain perviously used data. I want to make it clear all labels and text fields when application starts please any one help me Thanks in Advance.
Set the value of the fields as nil in ViewWillAppear or in ViewDidLoad methods.
Try adding this to your code:
textFieldname.stringValue = #"";
Do this in viewwillappear method:
label.text = #""; //and all other labels
txt.text = #""; //and all other textFields
Set the value of fields and labels nil i.e label.text = #""; in ViewWillAppear it'll clear fields and labels when come back to tab.
I have NSMutableDictionary that I'm retrieving text from. I"m trying to display this text into a tableview cell along with some other text that I want added with it. Here's my non-working code:
[[cell name] setText:(#"Name:%#",[NameDict valueForKey:#"name"])];
I've even tried stringWithFormat and still can't get it to work. I can't get the Name: part to display into the cell along with NameDict value for that key. Any ideas what I'm doing wrong here? Thanks.
I'm not sure where you are getting [cell name] from, but this would be a better solution for you based on your code:
[[cell name] setText:[NSString stringWithFormat:#"Name:%#",[NameDict objectForKey:#"name"]]];
If you are trying to place that text as the cell text, use:
cell.textLabel.text = [NSString stringWithFormat:#"Name:%#",[NameDict objectForKey:#"name"]];
I've been looking all over the 'net for information/examples...
I'm trying to change the line spacing of text inside a UITextView object to double spaced. I thought you could do it via Core Text, but haven't found a solution!
Any example code or information would be greatly appreciated! Thanks!
You don't have to look all over the net. A look at the documentation for UITextView is sufficient to determine that changing the line spacing is not supported by that control.
With Core Text you have complete control over the layout of the text you draw, of course. But it would be a lot of work to rewrite a UITextView-like control from scratch.
This question was asked before iOS 6. I'd like to post an updated answer for those who would like a way to do this.
This can be done now with iOS 6 and later by using an NSAttributedString. UITextView now accepts an attributed string as one of its properties. You can do all sorts of text manipulation with attributed strings, including line spacing. You can set the min and max line heights for the paragraph style attribute of the string.
Check out the NSAttributedString Class Reference for more information.
Here's a sample of what you could do:
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.minimumLineHeight = 21.0f;
paragraph.maximumLineHeight = 21.0f;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:#"Test text line 1\nTest text line 2\nTest text line 3" attributes:#{NSParagraphStyleAttributeName: paragraph}];
textView.attributedText = attributedString;
You can use NSLayoutManagerDelegate. Add that delegate to your ViewController or UIView class (etc.) and then when you create your UITextView...
yourTextView.layoutManager.delegate = self
Add this delegate method:
func layoutManager(layoutManager: NSLayoutManager, lineSpacingAfterGlyphAtIndex glyphIndex: Int, withProposedLineFragmentRect rect: CGRect) -> CGFloat {
return 5 //Whatever you'd like...
}