I have the following code:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"My Title" forState:UIControlStateNormal];
button.frame = myCustomRect;
UIColor *fontColor = [UIColor colorWithRed:0.43 green:0.84 blue:0.86 alpha:0.9];
[button setTitleColor:fontColor forState:UIControlStateNormal];
button.backgroundColor = [UIColor whiteColor];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.titleLabel.font = [UIFont fontWithName:@"Cooperplate" size:9];
[button addTarget:self
action:@selector(moreDetails:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
I am trying to add a button programmatically to the view.
MyCustomRect’s parameters are (0,0,75,50).
Two things:
a) No matter what font I enter, it always shows the System font.
b) The size also doesn’t change at all. I tried increasing the font size and it doesn’t change and I tried reducing the font size and it doesn’t change either.
What am I doing wrong?
You can use your own custom fonts in your project as mentioned here
Once you add a custom font to your project, you can use it as,
Image