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 a view. MyCustomRect Parameters: (0,0,75,50).
Two things: a) No matter what font I entered, it always displays the system font. b) Size also does not change at all. I tried to increase the font size, and it did not change, and I tried to reduce the font size, and it will not change either.
What am I doing wrong?
source share