I have the following code for setting up text in a UIButton
[self.fullListButton_ setTitle:[NSString stringWithFormat:#"%d", [self.newsfeedItem_.newsfeedToSubjects count] - 3] forState:UIControlStateNormal];
The issue is I can't seem to set the font for this. How do I do so?
In the newer version of iOS:
UIButton * myButton;
myButton.titleLabel.font = [UIFont systemFontOfSize: 12];
Or any other font mechanism.
Look here for the UIButton portions:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/occ/instp/UIButton/titleLabel
And here for the UIFont stuff:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIFont_Class/Reference/Reference.html
In your code:
self.fullListButton_.titleLabel.font = [UIFont systemFontOfSize: 12];
or
self.fullListButton_.titleLabel.font = [UIFont fontWithName:#"Arial" size:12];
Related
cell.textLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:8.0];
Is it possible to pass the name of the font family and size dynamically to label text of the cell in iPhone?
NSString *selectorString =#"Helvetica-Bold";
cell.textLabel.font = [UIFont fontNamesForFamilyName:#"%#",selectorString];
Try this its helps you.
UILabel *titlelbl=[[UILabel alloc] initWithFrame:CGRectMake(80, 0, 150, 40)];
titlelbl.font = [UIFont fontWithName:#"Helvetica-Bold" size:17];
titlelbl.textAlignment=UITextAlignmentCenter;
titlelbl.textColor=[UIColor blackColor];
you can set like this
float fontSize = 14.0f;
NSString *selectorString =#"Helvetica-Bold";
cell.textLabel.font = [UIFont fontWithName:[NSString stringWithFormat:#"%#",selectorString] size:fontSize];
#define FONT_HELVETICA_BOLD #"Helvetica-Bold"
#define FONT_SIZE 14.of
cell. textLabel.font=[UIFont fontWithName:FONT_HELVETICA_BOLD size:FONT_SIZE];
Can any one tell me that how can i get the map annotation title's font/style in a UIlabel
I want the exact style/font in the label ..
UILabel *name = [[UILabel alloc]init];
name.text = #"Hello Annotation";
name.textColor = [UIColor whiteColor];
[name setFont: [UIFont fontWithName:#"Helvetica" size:20.0]];
what else should i need to include to get the exact style as of the annotation title ?
try
[name setFont: [UIFont boldSystemFontOfSize:20.0]];
also play with shadow settings.
[name setShadowColor:[UIColor blackColor]];
[name setShadowOffset:CGSizeMake(0, -1)];
I have been trying to add this code into my project:
reasonLabel.font = [UIFont labelFontSize:15];
but I keep getting this warning:
Class method '+labelWithSize:' not found (return type defaults to 'id')
How would I fix this?
Thanks,
Seb
You can use with
[UIFont fontWithName:#"Arial" size:14]
or
[UIFont systemFontOfSize:14]
[UIFont labelFontSize] returns the standard system UILabel font size, it is not an initializer. You must use something like fontWithSize:(CGFloat)fontSize or systemFontOfSize:(CGFloat)fontSize
Use
reasonLabel.font = [UIFont systemFontOfSize: [UIFont labelFontSize]];
and if you want to create a smaller or bigger font, just add or subtract:
reasonLabel.font = [UIFont systemFontOfSize: [UIFont labelFontSize] + 2];
reasonLabel.font = [UIFont systemFontOfSize: [UIFont labelFontSize] - 1];
For bold fonts use this:
reasonLabel.font = [UIFont boldSystemFontOfSize: [UIFont labelFontSize]];
I would like to create an UIView that fits his content. The content is an UILabel with dinamic text.
UIView *myview = [ [UIView alloc ] initWithFrame:CGRectMake(10.0, 10.0, 700.0, 100.0)];
myview.backgroundColor = [UIColor redColor];
[self.view addSubview:myview];
UILabel *myLabel = [ [UILabel alloc ] initWithFrame:CGRectMake(10.0, 10.0, 500.0, 43.0) ];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.textColor = [UIColor whiteColor];
myLabel.backgroundColor = [UIColor blackColor];
myLabel.font = [UIFont fontWithName:#"Arial Rounded MT Bold" size:(36.0)];
[myView addSubview:myLabel];
myLabel.numberOfLines = 0;
myLabel.text = #"This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. ";
[myLabel sizeToFit];
I attach a screenshot:
Screenshot
Try this after [myLabel sizeToFit]:
[myView setFrame:myLabel.frame];
This will do the trick:
NSString *tempString = #"This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. This is an UILabel. ";
CGSize constSize = { 260.0f, 20000.0f };
CGSize textSizeTitle = [tempString sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constSize lineBreakMode:UILineBreakModeWordWrap];
UILabel *EventTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 260,textSizeTitle.height)];
[EventTitle setText:tempString];
[EventTitle setBackgroundColor:[UIColor clearColor]];
[EventTitle setFont:[UIFont fontWithName:#"TrebuchetMS-Bold" size:20]];
[EventTitle setNumberOfLines:0];
[EventTitle setUserInteractionEnabled:NO];
[EventTitle setTextColor:[UIColor whiteColor]];
[newsBox addSubview:EventTitle];
Just ensure, font size of textSizeTitle & EventTitle should be same.
How can I set the font of button label to Century Gothic Bold of size 46.
I'm using following code:
[self.titleLabel setFont:[UIFont fontWithName:#"Century Gothic-Bold" size:46]];
Is my code correct or not?
UIButton *NameBtn=[UIButton buttonWithType:UIButtonTypeCustom];
NameBtn=[[UIButton alloc]init];
[NameBtn setBackgroundColor:[UIColor clearColor]];
[NameBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
NSString *textb=[[self.searchList objectAtIndex:indexPath.row] objectForKey:#"name"];
CGSize constraintb = CGSizeMake(310 ,10);
CGSize sizeb = [textb sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:constraintb lineBreakMode:UILineBreakModeWordWrap];
[NameBtn setTitle:textb forState:UIControlStateNormal];
NameBtn.font = [UIFont fontWithName:#"Helvetica-Bold" size: 12.0];
NameBtn.frame = CGRectMake(85, 12, MAX(sizeb.width ,3.0f),12);
[NameBtn addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
NameBtn.tag=indexPath.row;
[self.view addSubview:NameBtn];
I think iOS doesnt support your font. But there is a font called AppleGothic.
see this link
http://www.prepressure.com/fonts/basics/ios-4-fonts
I used yesterday this:
onlineButton.titleLabel.font = [UIFont boldSystemFontOfSize:onlineButton.titleLabel.font.pointSize+3];
So try this:
yourButton.titleLabel.font = [UIFont fontWithName:fontName size:size];