I have to set the font size and font family of a dynamically created textView, so that it gives same appearance as the one generated using Interface builder. Any idea how to do this?
UITextView *textView
...
[textView setFont:[UIFont fontWithName:#"ArialMT" size:16]]
You try this
[textView setFont:[UIFont systemFontOfSize:15]];
or
[textView setFont:[UIFont boldSystemFontOfSize:15]];
or you want to give fontname and size then you try this
[textView setFont:[UIFont fontWithName:#"arial" size:16]]
There is a property called font in UITextView,
#property(nonatomic, retain) UIFont *font
You can do like this:
yourTextView.font = builderTextView.font
may be I am too late but wanted to post my answer as its most relevant with current SDK.
I have used following line of code and work like charm in iOS 8.0
Swift Version:
self.textView.font = [UIFont systemFontOfSize:fontSize];
where fontSize is CGFloat Value.
In IB, select the text area and use the inspector to set the editability (it’s next to the text color). To set the font, you have to bring up the font window (command-T). It may help to have some text in the view when you change the font and size.
textView.font = UIFont(name: "Times New Roman", size: 20)
This worked for me (Swift 4 using in Swift Playgrounds on Xcode).
Related
How to get the font style of UILabel? Whether it is Bold or italic ?
You will need to inspect the font name.
myLabel.font.fontName
http://developer.apple.com/library/ios/documentation/uikit/reference/UIFont_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006891-CH4-SW16
Try this one:
NSAttributedString *string=yourLabel.attributedText;
if ([[textFieldFontName rangeOfString:string] length] > 0){
NSLog(#"Bold");
}
if ([[textFieldFontName rangeOfString:string] length] > 0){
NSLog(#"Italic");
}
*Note if your string contains both then, this may not work
Select your label in the interface builder (xib or storyboard) and go to the Attributes Inspector. There click on the "T" by font and then set font to Custom.
Now you can change the font, size etc.
UILabel *myLabel;
myLabel.font = [UIFont fontWithName:#"fontName" size:16.0];//set font according your choice
myLabel.font = [UIFont boldSystemFontOfSize:16.0];//bold font
myLabel.font = [UIFont systemFontOfSize:16.0];//system font
Hope it's helpful for you....
i have to add custom font file .Name of file if #"sample font.ttf".I do following steps.
Drop the file (sample font.ttf) into your project. Open up your Info.plist file, create a key called UIAppFonts and make it an array. Add the filename of the font as a value
But it not working ..I thought the reason may by space in filename.when i get this file it was a compressed with filename #"sample_font.ttf".when i decompress it ,it removes #"_" and get "sample font.ttf"
Then i install it in font book .the name in window is first word file that is "sample"
I try with various way
UIFont *font = [UIFont fontWithName:#"sample font" size:14];
UIFont *font = [UIFont fontWithName:#"sample" size:14];
UIFont *font = [UIFont fontWithName:#"samplefont" size:14];
UIFont *font = [UIFont fontWithName:#"samplefont-Bold" size:14];
but not working. what exact font name should have to given. ios is 5.0 .Plz help me.
Just double click the font file and install it and then it will open Font book
go to Preview menu->>Show font info
There you can see the name of the font and use that name in UIFont *font = [UIFont fontWithName:#"nameAsSeenInShowFonts" size:14];
Note: The font file name and font name can be different. So in your .plist you use font file name and in your code you use font name
if you try in Ios5 I think you forgot to include your font file in TestApp target membershipI
Except all these, you can use an alternet option for custom fonts. I have implemented this concept jst before some days.
First download this. This is FontLabel. Drop it in your project.
Note that If u want to use fonts for label than only this will help u. If so, than u can use FontLabel object instead of ur label object with same behavior.
For exa.
FontLabel *label;
label = [[FontLabel alloc] initWithFrame:CGRectMake(75, 100, 104, 54) fontName:#"Script MT Bold" pointSize:30.0f];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = nil;
[label sizeToFit];
label.opaque = NO;
You can treat label object same as ur UILabel object. FontLabel is subclass of UILabel..
Did anybody used digital-7 fonts in UILabel, i found text to align in bottom(aligns too low on the Y axis instead of being in the vertical center of the label). do anybody has solution to show them center aligned?
What you're asking about, with that particular font, is that it aligns too low on the Y axis instead of being in the vertical center of the label. Some solutions:
get a font manager and fix the font by hand
adjust the UILabel instances or a UILabel subclass to push it up higher than it is. You could do this by intercepting a setFrame call, for instance.
As far as I can see, UIFont does not carry that information with it at all. It might, though: you can check some of the read-only properties of the font.
With that said, however, you still can't set properties on a font, so you cannot adjust it in this way.
try this..
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(148, 142, 130, 25)];
[testLabel setFont:[UIFont fontWithName:#"DBLCDTempBlack" size:20]];
[testLabel setText:#"MY Text"];
[testLabel setTextColor:[UIColor darkGrayColor]];
[testLabel setBackgroundColor:[UIColor clearColor]];
[testLabel setTextAlignment:UITextAlignmentCenter];
I had used custom fonts in my project earlier. Just you have to add the font.tff file in your project and set your font with setFont method
I have used UITextView in my application. Now this might be a dumb question but how can I change the font size of text in it.
if any1 can help with this would be appreciated.
thanks
you have to set font by code
yourtextViewObject.font = [UIFont systemFontOfSize:14];
Try this...
[yourtextview setFont:[UIFont boldSystemFontOfSize:13.0f]];
UITextView has a read-write font property declared:
#property(nonatomic,retain) UIFont *font;
The UIFont class declares a factory method:
+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize;
So create a new UIFont instance and then call -setFont: on your UITextView with the font instance.
When i use this line
[UIFont fontWithName:#"Arial" size:16] its work fine,but
[UIFont fontWithName:#"Arial Black" size:16] it crashes my app.....
In xib design there is the font name of Arial Black is available.But when i set using [UIFont fontWithName:#"Arial Black" size:16] this it crashes my app.. How can i set this font name to uilabel...
Can any one help me?
Check the return value of +[UIFont fontWithName:size:]. My guess is that "Arial Black" is not being found, and a nil font is being returned. Setting a UILabel's font to nil will crash.
To add - using +familyNames and +fontNamesForFamilyName methods in UIFont you can list all fonts available.
You need Arial-BoldMT
[UIFont fontWithName:#"Arial-BoldMT" size:16];
See here