How change size textlabel in UITableView - uitableview

i have problem. I have dynamic tableview. So i need change text size in my textLabel.
I tried:
one:
cell.textLabel.font = [UIFont systemFontOfSize:30.0f];
two:
cell.textLabel.font = [UIFont boldSystemFontOfSize:12.0];
three:
UIFont *myFont = [ UIFont fontWithName: #"Arial" size: 30.0 ];
cell.textLabel.font = myFont;
But my textlabel not changing. So detailtextlabel - change perfectly but text label - no. What i do wrong? thanks

You can try with the following..
but make sure you write this code before u setting your text
cell.textLabel.text=#"Your TEXT Goes Here";
UIFont *myFont = [ UIFont fontWithName: #"Arial" size: 18.0 ];
cell.textLabel.font = myFont;
hope it helps.

Related

Change UITableViewCell Font in iOS 8 and swift

I'm trying to change the font for my uitableviewcells,
I'm trying to use this at the moment with not success:
cell.textLabel.font = [UIFont .preferredFontForTextStyle("Avenir")];
Now i've read a lot on this and it seems I should use this instead :
cell.textLabel.font = [UIFont fontWithName: "Avenir" size:22];
Problem is fontWithName does not seem to exist in iOS 8
any ideas??
thanks
The thing is that this is not Swift (it is a kind of horrifying bastardization of Objective-C):
cell.textLabel.font = [UIFont fontWithName: "Avenir" size:22];
This would be Swift:
cell.textLabel.font = UIFont(name:"Avenir", size:22)
Try the following casting way:
cell.textLabel.font = UIFont(name: "Avenir", size:22);

Vertically centering a UITextField's attributedPlaceholder

I am currently unable to vertically align an attributedPlaceholder inside a UITextField and I've no idea why.
Here's what I am doing:
self.addressBar = [[UITextField alloc] initWithFrame: CGRectMake(...)];
self.addressBar.backgroundColor = [UIColor whiteColor];
self.addressBar.attributedPlaceholder = [[NSAttributedString alloc] initWithString:#"Placeholder text"
attributes:#{
NSForegroundColorAttributeName: [UIColor colorWithRed:79/255.0f green:79/255.0f blue:79/255.0f alpha:0.5f],
NSFontAttributeName : [UIFont fontWithName:#"Gotham-BookItalic" size:14.0],
}
];
self.addressBar.delegate = self;
self.addressBar.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.view addSubview:self.addressBar];
And here's what happening:
It's quite clear that this happens due to the fact that the UITextFieldLabel's height is 10px smaller than the UItextField itself, but I can't seem change that.
This only happens using an attributedPlaceholder though; the default placeholder property works just fine.
Any ideas?
Use NSParagraphStyle to increase minimum line height:
NSMutableParagraphStyle *style = [self.addressBar.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];
style.minimumLineHeight = self.addressBar.font.lineHeight - (self.addressBar.font.lineHeight - [UIFont fontWithName:#"Gotham-BookItalic" size:14.0].lineHeight) / 2.0;
self.addressBar.attributedPlaceholder = [[NSAttributedString alloc] initWithString:#"Placeholder text"
attributes:#{
NSForegroundColorAttributeName: [UIColor colorWithRed:79/255.0f green:79/255.0f blue:79/255.0f alpha:0.5f],
NSFontAttributeName : [UIFont fontWithName:#"Gotham-BookItalic" size:14.0],
NSParagraphStyleAttributeName : style
}
];
You could also override a - (CGRect)placeholderRectForBounds:(CGRect)bounds; method in UITextField subclass.
It's messy, but it works :)
Placeholder will not be aligned if your textfield's text font is different than that of textfield's placeholder's font. Make sure both the font are same if you want to align properly or else you can follow kean's answer.
textField.font = [UIFont fontWithName:#"HelveticaNeue" size:12];
textField.attributedPlaceholder =
[[NSAttributedString alloc] initWithString:#"Enter fruit/vegetable name"
attributes:#{
NSFontAttributeName : [UIFont fontWithName:#"HelveticaNeue" size:12.0]
}
];
If you are using attributedPlaceholder, make sure to set the font of the textField to be the same font you use in the attributedString.
As #Kean answered. And you should do it like this in Swift 4:
let defaultParagraphValue = self.textField.defaultTextAttributes[NSAttributedStringKey.paragraphStyle.rawValue]
if let lineHeight = self.textField.font?.lineHeight,
let style = defaultParagraphValue as? NSParagraphStyle,
let mutableStyle = style.mutableCopy() as? NSMutableParagraphStyle {
mutableStyle.minimumLineHeight = lineHeight - (lineHeight - UIFont.systemFont(ofSize: 16).lineHeight) / 2.0
let placeholderAttribute = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16),
NSAttributedStringKey.paragraphStyle: mutableStyle]
let attributeHolder = NSAttributedString(string: "Placeholder String",
attributes: placeholderAttribute)
self.textField.attributedPlaceholder = attributeHolder
}
This works in iOS 10, iOS 11 fix this issue.

how to change font size of label without changing font family in xcode

how to change font size of label without changing font family in xcode6 ?I am using following line of code:
lblMain.font = [UIFont systemFontOfSize:22];
Here's an example:
lblMain.font = [UIFont fontWithName:#"HelveticaNeue" size:22];
Or - you can even use the current font:
lblMain.font = [lblMain.font fontWithSize:22];
NSString *fontName = lblMain.font.fontName;
CGFloat fontSize = lblMain.font.pointSize;
[lblMain setFont:[UIFont fontWithName:fontName size:NEWSIZE]];
Use following code, if you just want to change font size keeping the same font family:
lblMain.font = [UIFont fontWithName:lblMain.font.fontName size:22.0f];
OR
You can also use this code:
lblMain.font = [lblMain.font fontWithSize:22.0f];
[lblMain setFont:[UIFont fontWithName:#"HelveticaNeue" size:17]];

ios 7 typography on labels and UIFont

I have the following code:
UILabel *registerLabel = [ [UILabel alloc ] initWithFrame:CGRectMake(20.0, 90.0, [self screenWidth], 43.0) ];
registerLabel.textAlignment = NSTextAlignmentLeft;
registerLabel.textColor = [UIColor whiteColor];
registerLabel.backgroundColor = [UIColor blackColor];
registerLabel.font = [UIFont fontWithName:#"Helvetica Neue" size:(20.0)];
//registerLabel.adjustsFontSizeToFitWidth = YES;
registerLabel.text = #"Register";
But I see in some of the ios 7 demo apps (like calendar) the font is large but much thinner. I tried using Helevetica Neue Light but that doesn't work. Is there a way to make the font thinner or what font are they using?
I found the answer to be this:
registerLabel.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:(36.0)];
.font is what you need

Change text size in different lines of textlabel cell uitableview

I created a uitableview and in every cell there's a textLabel.
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = [NSString stringWithFormat:#"Hello\n how are you?"];
UIFont *myFont = [ UIFont fontWithName: #"Novel" size: 6.0 ];
cell.textLabel.font = myFont;
Can i set the font of "Hello" to 10 and the font of "how are you?" to 6?
Thank you!
Do as per the following:
UILabel *flabel = [[UILabel alloc]init];
flabel.text = #"Hello";
flabel.font = [UIFont fontWithName:flabel.text size:10];
UILabel *slabel = [[UILabel alloc]init];
slabel.text = #"How are you?";
slabel.font = [UIFont fontWithName:slabel.text size:6];
cell.textLabel.text = [NSString stringWithFormat:#"%#\n%#",flabel.text,slabel.text];
I have created two different labels having different font size and set it to cell textlabel by concatenation of both strings.
Hope this should work.

Resources