UITextField placeholder has different font size - ios

I have a few textFields made in interface builder and then a few made programatically. The placeholder text seems to have different sizes. It seems I should be able to get the same font without subclassing UITextField. I am just trying to recreate the a textfield which looks like the one from interface builder.
UITextField *textField = [[UITextField alloc] init];
textField.placeholder = string;
[textField setTranslatesAutoresizingMaskIntoConstraints:NO];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:textField];
textField.returnKeyType = UIReturnKeyNext;
textField.inputAccessoryView = [[QEDCKeyboardAccessory alloc] initWithDelegate:self];
textField.delegate = self;

You can do it by programmatically setting up the value for the key #"_placeholderLabel.font"
[self.input setValue:[UIFont fontWithName: #"American Typewriter Bold" size: 20] forKeyPath:#"_placeholderLabel.font"];
and also You can override drawPlaceholderInRect to do this....
- (void) drawPlaceholderInRect:(CGRect)rect {
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:13]];
}

You can set an attributed string on the placeholder. If your interface builder text fields are using attributed strings it uses the same attributes, except for the foreground color.
See this doc:

The problem may be that, when you are about to creation of UITextField via programmatically and IB, The Font size of UItextfield are different .
You just need to set the Font size are Equal by IB as well as Programmatically,
There is no separate font functionality for PlaceHolder

They never have different size, thats the size of the textSize for UItextfield. Please check the size of TextSize from its property

Related

how to set different font size to text of button name in storyboard

I want to make application in which i want to make a login screen. It has button having name "Log inn with Facebook". I want font size of Facebook greater than Log in with. How can I set it in main storyboard?Can anyone plz help me?
Follow these steps-
1.Select button
2.Change its type to custom in Attributes inspector
3.Change its title from Plain to Attributed
4.Change the part of title which you want to be set bold
A solution would be to have a UIView with two different UILabel as subviews ( your "Log in with" label and your "Facebook" label ).
Then, above this UIView you could have a UIButton with a white background and an alpha equal to 0.01 so the button would be touchable but invisible.
This UIButton would be the functional part of your UI.
NSMutableAttributedString *titleText = [[NSMutableAttributedString alloc] initWithString:#"Login with Facebook"];
[yourbutton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
// Set the font to bold from the beginning of the string to the ","
[titleText addAttributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName] range:NSMakeRange(0, 10)];
// Set the attributed string as the buttons' title text
[yourbutton setAttributedTitle:titleText forState:UIControlStateNormal];
Instead of creating NSAttributedString create NSMutableAttributedString then you can just set the string like this.

UISearchBar placeholder text color/location

However, I've applied different patches still I'm not able to fix placeholder text position and text color for UISearchbar.
But when I type something, it's showing up at a proper place.
What's the reason?
This is how you can change the colour of your placeholder text:
UITextField *searchField = [self.searchBar valueForKey:#"searchField"];
searchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:#"Some Text"];
UILabel *placeholderLabel = [searchField valueForKey:#"placeholderLabel"];
placeholderLabel.textColor = [UIColor blueColor];
As for the position, by default, placeholder text is vertically centre positioned in the UISearchBar. From your screenshot, it appears to me that there are few new line characters in the end of the text.
there's a category created on UITextField, inside it, the placeholder text is drawing. I just corrected the frame and now everything works fine, even that solve the color issue as well.

Adding default text to UITextView

I was wondering how to display a default prompt in a UITextView. If I wanted the user to type a description in a text view, the UITextView could have "description" printed in it, and when the user starts to type, it disappears.
For UITextField, there is the placeholderText property, which will display a grayed out text that is removed once the user starts typing.
For UITextView, you can use a custom implementation, such as SZTextView, which implements a similar functionality of a placeholder text.
It wont be a wise idea to use a third party uitextview for placeholder property.
Follow these steps and you will achieve what you need-
set- textview.textcolor=[uicolor greycolor];
textview.text=#"Your initial placeholder text";
Now in -textViewShouldBeginEditing write these lines of codes-
if(textview.color==[uicolor greycolor]){
textview.color=[uicolor blackcolor];
textview.text=#"";
}
Cheers.
The below solution from #svmrajesh isn't complete. You still need to implement an auto-delete functionality so the default text deletes as soon as the user selects the textView.
In my implementation I set the text in the UITextView to lightGrayColor initially so that it looks like default text
[textView setTextColor:[UIColor lightGrayColor]];
Then in the header file I implement the UITextViewDelegate.
#interface YourViewController <UITextViewDelegate>
Then I set the UITextView delegate to self.
[textView setDelegate:self];
Then simply I implement the following delegate method which is fired when the user selects the textView to start typing in their text. The first thing it does is to check if the text color is still set to lightGray.
If it is then the default text is still being displayed, so it is deleted and the textColor is set to black. This simple solution works well for me.
-(void)textViewDidBeginEditing:(UITextView *)textView
{
if(textView.textColor == [UIColor lightGrayColor])
{
textView.textColor = [UIColor blackColor];
textView.text = #"";
}
}
Try this....
For UITextView :
UITextView *myUITextView = [[UITextView alloc] init];
myUITextView.delegate = self;
myUITextView.text = #"placeholder text here...";
For UITextField :
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 200)];
textField.placeholderText = #"Enter your text here";
[self.view addSubview textField];

Change UIFont type globally respecting size and other atributtes in iOS

I have an app developed for iOS6 and I am just migrating to iOS7
there's a new font used with this interface: "HelveticaNeue-Light"
I want to replace my system font to this one globally for buttons, labels, textviews, textfields to this, respecting all other attributes (if font is bold, italic, font-size...)
how can I do that
I was applying:
[[UILabel appearance] setFont:[UIFont fontWithName:#"HelveticaNeue-Light" size:15.0f]];
but it changes size of all my fonts, if I set the size to default in zero my fonts dissappear
also tried this:
[[UILabel appearance] setFont:[UIFont preferredFontForTextStyle:#"HelveticaNeue-Light"]];
but this changes my font to a small size that's not the solution as well
thanks in advance for your support
You probably need subclass UILabel and override awakeFromNib like below:
#implementation MyUILabel
- (void)awakeFromNib
{
[super awakeFromNib];
self.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:self.font.pointSize];
}
#end

Cannot remove border of UITextField dynamically

I want to remove the border of UITextField dynamically.
I tried [stringTextField setBorderStyle:UITextBorderStyleNone];
but nothing happened. Any idea?
Is the TextField already displayed in the view when this happens? If so, you (probably) need to execute the following:
[stringTextField setBorderStyle:UITextBorderStyleNone];
[stringTextField setNeedsDisplay];
in order for the view to redraw the TextField, sans border. Note that there's no guarantee the system will immediately redraw the textField. You're indicating to the system that you'd like the field to be redrawn.
With an existing UITextField I found that this worked:
[textField setEnabled:NO];
[textField setBorderStyle:UITextBorderStyleNone];
while this did not (the border remained in the view):
[textField setBorderStyle:UITextBorderStyleNone];
[textField setEnabled:NO];
Try this ones.
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.borderStyle = UITextBorderStyleNone;

Resources