Hello all!
I'm working on dynamic buttons depending on the plist file.
The buttons show up fine, however I'm in a bit of pain with calculating the width of the buttons, because they are not aligned to the left like they suppose to.
What is the best way to calculate the width of my buttons ?
(I assume it has to do with the width of my buttons)
When I add a background color to the buttons, I see that the frame is correct, but the text is not.
I'm working on dynamic buttons depending on the plist file.
The buttons show up fine, however I'm in a bit of pain with calculating the width of the buttons, because they are not aligned to the left like they suppose to.
Code:
for(int a=0; a < [currentButtons count]; a++) {
//adding 10 px for each character, plus 10 extra for some 'padding' in case there is a background color
float width = ([[currentButtons objectAtIndex: a] length] * 10) + 10;
float horizPos = 10;
if(buttonPosition == 2) {
horizPos = centerX - (width / 2);
}
if(buttonPosition == 3) {
horizPos = naviView.frame.size.width - width - 10;
}
UIButton *theButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[theButton setTag: a];
[theButton setTitle:[currentButtons objectAtIndex: a] forState:UIControlStateNormal];
theButton.frame = CGRectMake(horizPos, yOffset, width, 23.0);
[theButton.titleLabel setTextAlignment: NSTextAlignmentLeft];
What is the best way to calculate the width of my buttons ?
(I assume it has to do with the width of my buttons)
When I add a background color to the buttons, I see that the frame is correct, but the text is not.
Last edited: