0

enter image description here

I want same textfield or any control in iOS Objective-C, like this image google wallet input entry.

Chirag Kothiya
  • 955
  • 5
  • 12
  • 28
prince k
  • 21
  • 1
  • 1
  • 5
  • possible but did you search on Google or simple on other open hub. As beginner explain your question as much possible & avoid negative marking. – Gagan_iOS May 15 '17 at 07:53
  • thanks for responds, can you please give me any reference link? becuase i have done lots of search and i can't found same like my need. – prince k May 15 '17 at 07:56
  • look few examples I have never run them but should work 1 https://github.com/EddyBorja/MLPAutoCompleteTextField 2 https://github.com/jverdi/JVFloatLabeledTextField 3 https://github.com/TheMrugraj/MVAutocompletePlaceSearchTextField Also there is an openhub name cocoacontrol.com go on this site & search for ur ui – Gagan_iOS May 15 '17 at 08:08
  • Hey @Gagan, thanks but i already checked all link provided by you, and also i have checked on cocoa control, ioslibs and all hub, and i can't found solution from any where, thats why i am put my question here. – prince k May 15 '17 at 08:13

1 Answers1

1

Yes totally possible Use NSAttributed String here is the link NSAttributedString

Create 2 NSDictionary one for smaller fontSize and one for Bigger fontSize. in the small font size Attributed Dictionary the size for the NSBaselineOffsetAttributeName is used to move the small font up or down change the value to see the effect.

// I have added the attribute for font color as well so it should look the same as picture above
NSDictionary *smallFontSize = @{
                                NSFontAttributeName : [UIFont systemFontOfSize:10],
                                NSBaselineOffsetAttributeName : [[NSNumber alloc] initWithInt:10],
                                NSForegroundColorAttributeName : [UIColor grayColor]
                                };

Second dictionary is very simple it only contains the font Size

NSDictionary *bigFontSize = @{
                              NSFontAttributeName : [UIFont systemFontOfSize:25]
                              };

Declare NSMutableAttributedString not AttributedString pass in the samllFontSize

// I have directly passed the $ sign but you will pass it as a property
NSMutableAttributedString *mutableAttriString = [[NSMutableAttributedString alloc] initWithString:@"$" attributes:smallFontSize];

Now create two new AttributedStrings these 2 can be attributedString because we are not manipulating them

// You will be passing the amount and decimals as properties
NSAttributedString *amount = [[NSAttributedString alloc] initWithString:@"10" attributes:bigFontSize];
NSAttributedString *decimalAmount = [[NSAttributedString alloc] initWithString:@"00" attributes:smallFontSize];

Now try to append both amount and decimalAmount to the mutableAttributedString that was the reason we made the first one mutable so we can append to it later

[mutableAttriString appendAttributedString:amount];
[mutableAttriString appendAttributedString:decimalAmount];

Each label has a property called text and another one called attributedText add it to the attributedText property

self.priceLabel.attributedText = mutableAttriString

Here is the screenshot of the label change the font and colours to your liking.

Screenshot

Khalid Afridi
  • 913
  • 5
  • 12
  • hello @khalid thanks for responds, i know it possible, can you please give me example of code. – prince k May 15 '17 at 07:57
  • please see this example [Top-aligning text of different sizes within a UILabel ] (http://stackoverflow.com/questions/15537033/top-aligning-text-of-different-sizes-within-a-uilabel) – Khalid Afridi May 15 '17 at 11:05
  • Done added a quick example hope it's what he want's – Khalid Afridi May 15 '17 at 19:32
  • Hello @Khalid afridi, Thanks for your Support, yes your provided link is worked for me, because i need this thing when user types on textfield then i have call (shouldChangeCharactersInRange method of textfield) i need to just do minor changes. but thanks for you support. it is very useful code. – prince k May 16 '17 at 08:15
  • @KhalidAfridi for display this amount on label, your provided code is work like charm. thank you very much. – prince k May 16 '17 at 08:16