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.
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....
Is there any easy way to set a text field's hint to italic, while keeping the actual text non-italicized? The image below shows what I'm trying to accomplish, but doesn't actually work, as text typed into the first text field is still italicized.
If there's no easy way to do this, I'm thinking that I'll have to implement methods on each of the text fields to check the length of the text, and if zero apply the italic font. This would work, right? Is there a better way?
Try this:
UIFont* italicFont = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[yourTextField setValue:italicFont forKeyPath:#"_placeholderLabel.font"];
EDIT:
Ok, here is another (legal) way to do it:
1.Subclass UITextField and override drawPlaceholderInRect::
TextFieldSubclass.h:
#interface TextFieldSubclass : UITextField
#end
TextFieldSubclass.m:
- (void) drawPlaceholderInRect:(CGRect)rect
{
[[UIColor lightGrayColor] setFill];
UIFont* italicFont = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
[[self placeholder] drawInRect:rect withFont:italicFont];
}
2.Change your UITextField class and set it to TextFieldSubclass:
And that's it. Enjoy.
As I get strings of text down from my database, I need to know how big to make the UITextField and how big to make the Cell of the table that contains the UITextfield.
Are there any clever methods that can determine this? Since it will of course depend on the textfield width and the font used.
Thanks
-Code
NSString has a method sizeWithFont:contrainedToSize: that will give you to the size of a string with a particular font:
UIFont *font = [UIFont systemFontOfSize:12.f];
CGSize size = CGSizeMake(textView.frame.size.width, 1000.f);
CGSize stringSize = [myString sizeWithFont:font constrainedToSize:size];
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).
What is the fastest/simplest way to change only the size of the existing font on a UIButton? (pointSize is read-only)
Thanks in advance.
UILabel* titleLabel = button.titleLabel;
titleLabel.font = [titleLabel.font fontWithSize:12345];