I have a label in center of my screen and would like for the user to be able to change the font of this label. Can I access the font feature of the label programmatically, so that I can define and specify a function that would enable the user to do so?
UIFont *myFont = [UIFont fontWithName:#"HelveticaNeue" size:15];
[mylabel setFont:myFont];
Related
I'm facing this problem:
I have a tableView and a customCell, on my custom cell class I set font size and font colors for the labels that I have there, my issue is that in order to calculate the heightForRowAtIndexPath I don't have access to the labels font sizes, what I do in that method create temporary labels with the same text value that I set on the custom cell class and calculate the label height in order to set the heightForRowAtIndexPath height depending on the content but since I don't have the correct font it gives me a different height and I see spaces between each cell, is there any way to solve this?
Why not create global macros for the different font sizes.
#define LABEL1_FONT [UIFont fontWithName:#"Helvetica Neue" size:17]
Then you can make the check for the height:
UILabel *gettingSizeLabel = [[UILabel alloc] init];
gettingSizeLabel.font =LABEL1_FONT;
gettingSizeLabel.text = yourText;
CGSize maximumLabelSize = CGSizeMake(291, 9999);
CGSize expectedSize = [gettingSizeLabel sizeThatFits:maximumLabelSize];
// Get height required for label title
float lineHeightInfo = expectedSize.height / LABEL1_FONT.lineHeight;
Is it possible to fit in a text when the font size and the label heights don't match.
bigData = [[UILabel alloc] initWithFrame:(CGRect){20, 20, 100, 23}];
bigData.textColor = [UIColor colorWithHex:0xffffff alpha:1];
bigData.font = [UIFont fontWithName:#"Helvetica" size:32];
The label height is 23 and the font size is 32. This causes a portion of the text to be hidden. Is there anything logically wrong?
You will either need a label whose height is greater or decrease the font size, or use bigData.adjustsFontSizeToFitWidth
So the answer is "NO" you can't fit a font that is greater than the height of a UILabel
I am trying to set custom font.
Font is working with UILabel.
When I tries to use for UITextView, its not working. UITextView is taking default font.
Any idea how to use custom font for UITextView.
Code I am using is as below.
attributedString = [[NSMutableAttributedString alloc] initWithString:text
attributes:#{ NSFontAttributeName : [UIFont fontWithName:#"GEDinarOne-Medium"
size:15], NSLigatureAttributeName: #2}];
abtUsText.attributedText = attributedString;
abtUsText.textAlignment = NSTextAlignmentRight;
abtUsText.textColor = cb60756;
I am using attributedString to get working with iOS 6.
iOS 7 is giving proper font, but iOS 6 is using default font for UITextView only.
Edit 1
I am using arabic font as GEDinarOne-Medium
Edit 2
This is not duplicate of what is mentioned above as my case is with arabic font and not english font. Mentioned in duplicate works with english custom fonts only.
After I investigate custom font (especially arabic) is not working UITextView using attributedString, below is what I did.
I just wanted to display the text in UITextView (for About Us in my app) as it has long text and I wanted scrolling option.
Below is what I did.
Add UIScrollView
Add UILabel inside UIScrollView
Assign text to UILabel.
abtUsLabel.attributedText = attributedString;
Make label sizeToFit
[abtUsLabel sizeToFit];
This is very important step, else it won't work.
Set scrollview contentSize as per label height.
[abtUsScrollView setContentSize:CGSizeMake(abtUsScrollView.frame.size.width, abtUsLabel.frame.size.height)];
Done... now if the Label is longer, we can scroll it.
I am trying to implement a function that can change uilabel font size, I can zoom uilabel size(is uilabel.size) , then automatic change the uilabel's font size, the example app is InstaText!
label.font = [UIFont fontWithName:#"Your desired font" size:newSize];
or you could do it even easier:
By looking here UILabel - set property adjustsFontSizeToFitWidth to YES
Is there a way to edit a UITextField's font size with a UIStepper? i.e, tap the add button and the UITextField's font size increases by 1 or 5? So far I have tried [textField adjustsFontSizeToFitWidth:value]; with no luck. How could I do this? Also, if I can't control the font size with a UIStepper, how else can I edit the font size? Thanks
I think you should be using:
[textField setFont:[UIFont systemFontOfSize:value]];
UIFont *textFont = [UIFont fontWithName:#"Helvetica-Bold" size:8.0];
[textField setFont:textFont];
Try This...