Need to Customize the UIButton with attributed string as shown in figure - iphone

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.

Related

Showing emoji in a UILabel?

Not sure what I'm missing here, and searching hasn't helped me. I want to display emoji characters in a UILabel, and this isn't doing it:
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont fontWithName:#"AppleColorEmoji" size:16.0];
label.text = [NSString stringWithFormat:#"%C", 0x1F431];
// ... etc.
Works fine with other non-letter unicode characters, e.g. chess pieces, but not with any emoji characters that I have tried.
To use Emoji's just press Control+command+space (⌃⌘Space). No need of using unicode for emoji.
You are probably not using the correct encoding for your emoji characters. For instance in your example I think you are looking for something like this:
label.text = [NSString stringWithFormat:#"%C", 0xe04f];
Have a look at this table to get the encodings you need.
In xcode just go to the top bar and click EDIT > EMOJIS & SYMBOLS and an emoji box will pop up and you can literally add it to any text in the app, even works in the interface builder if you need to add it to the text of a uilabel there.
In Swift you can do:
label.text = "🐈"
Be sure to include the quotes. Otherwise you'll be setting the text to whatever is in the variable.
The following would display as "cat":
let 🐈 = "cat"
label.text = 🐈
The unicode 6.1 encodings work as well, but you would have to specify them like this:
label.text = #"\U0001F431";

how to change the font color of the special characters in a UITextview text

i am using this code to show some text in UITextview...in ViewDidLoad Method
self.fontSize = 23.0;
for(NSUInteger idx = 0; idx < [delegatee.allSelectedVerseEnglish count]; idx++) {
[combined appendFormat:#" %d %#",
idx + 1,
[delegatee.allSelectedVerseEnglish objectAtIndex:idx]];
};
maintextview.text =combined;
maintextview.textColor= [UIColor colorWithRed:0.376f green:0.282f blue:0.173f alpha:1.0f];
maintextview.font = [UIFont fontWithName:#"Georgia" size:self.fontSize];
combined has the text which includes numeric charter also,how can i identify the numeric character and put brown color and change font to Georgia-Bold only of numercharacters.is it possible by using NSSanner or NSregular expression or something like that?.
how to do this?
Thanks in advance.
You cannot do this on a regular text view. It does not allow formatting (although this is a greatly desired feature by many developers). What you need to do is use Core Text and NSAttributedString with a custom view. However, this is very difficult if you need to use selection, or have it be editable.
alternate option is to make an HTML page and put web View instead of the TextView.
it saves your time.

How to replace text in UITextView with selected range?

I want to replace the text in UITextView text in selected range. This is my question. Here i mention what i did? and what i want to do?. I have an UITextView and entered the below text in textview.
Ask question here, i have saved the range in of the text in textview. The text range is {17, 0}. I take the NSRange in -(void) textViewDidChange:(UITextView *)textView delegate.
Now i want to replace the text question with answer and i want to replace the text here with them. The UITextView.text look like this,Ask answer them` after replaced the texts.
How can i replace the texts with the selected ranges? Can you please help me? Thanks in advance.
Since iOS 7 there is the textStorage in the textView that inherits from NSMutableAttributedString so you can use those methods:
Objective-C
[self.textView.textStorage replaceCharactersInRange:withString:];
or
[self.textView.textStorage replaceCharactersInRange:withAttributedString:];
Swift
textView.textStorage.replaceCharacters(in: range, with: string)
Well... I'm not sure to understand correctly what you're trying to do, but if your goal is to change some characters in a selected range you can follow these steps:
Get your UITextView content and put it in a NSString:
NSString *textViewContent = textView.text;
Change the characters in the range you want:
NSString *newContent = [textViewContent stringByReplacingCharactersInRange:range withString:replacement];
Replace old content with new one:
textView.text = newContent;
Anyway if you just want to replace Ask question here with Ask answer them the fastest solution is just:
textView.text = #"Ask answer them";
Well solution from top of my head..
NSArray *Dividedstring = [[self.TextView.text] componentsSeparatedByString:#" question here "]; // this will divide the string into two parts ..one before question here and second after question here.
NSString * firstpart = [Dividedstring objectAtIndex:0];
NSString * secondpart = [Dividedstring objectAtIndex:0];
self.TextView.text = [NSString stringwithFormat:#"%# answer here %#",firstpart,secondpart];

iPhone:How to add "Degree" symbol in UILabel string text?

I want to include "degree" symbol for weather report as 45 degree C. How to add degree symbol in string to include that UILabel?
If anybody knows it, please share to me.
Thank you.
Shift-option-8?
In Swift
cell.lblTemperature.text = NSString(format:"23%#", "\u{00B0}") as String
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:#"80\u00b0c"];
[attributedString setAttributes:#{NSFontAttributeName : [UIFont fontWithName:#"Helvetica-light" size:10.0]
, NSBaselineOffsetAttributeName : #22} range:NSMakeRange(2, 2)];
//asign this as a
examplelabel.attributedtext = attributedString;
In Xcode 8.0:
Press Control+Command+Space Bar or Xcode->Edit->Emoji & Symbols, later search the degree symbols from pop-up screen.
You can easily add UILabel or TextView components.

What is the best way to display long file name in UITablView

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.