Reputation: 6490
I am new to iPhone,
xpos=30;
ypos=40;
for(int i=0;i<[MyArray count];i++)
{
if(i!=0)
{
if (i%4==0)
{
ypos+=180;
xpos=30;
}
else
{
xpos+=200;
}
}
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(xpos, ypos, 110.0, 130.0);
[button setImage: [UIImage imageNamed:@"ibook2.png"] forState:UIControlStateNormal];
[button setTitleEdgeInsets:UIEdgeInsetsMake(ypos, xpos, 0.0, 0.0)];
[button setTitle:[NSString stringWithFormat:@"%@", [MyArray objectAtIndex:i]] forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[self.view addSubview:button];
}
i am able to see button but unable to see my text on the UIButton.
Any help will be appreciated.
Upvotes: 2
Views: 3254
Reputation: 1145
Please set buttons background image.You have set buttons image. Please use this:
[button setBackgroundImage:[UIImage imageNamed:@"blue_button.png"]
forState:UIControlStateNormal];
For Wrapping button title User:
[button setTitle:@"Test button name 123" forState:UIControlStateNormal];
button.titleLabel.numberOfLines=2;
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
Upvotes: 4
Reputation: 3653
You can't see the text because you have used setImage: function of button. At a time you can display image or button on text but you can add image as a background so you can see both image and tittle. In short set image as a background.
[btn setBackgroundImage:[UIImage imageNamed:@"imageName"] forState:UIControlStateNormal];
Please also remove the line of setting inset.
Upvotes: 2
Reputation: 11026
if you image is too big then it will only show the image and text get truncated due to image as text will be visible after image, try using setBackground image or try small resolution image or setImageEdgeInsets .
Upvotes: 0
Reputation: 11338
Rather then setting
[button setImage: [UIImage imageNamed:@"ibook2.png"] forState:UIControlStateNormal]; // This will not allow you to set Button title.
You have to use :
[button setBackgroundImage: [UIImage imageNamed:@"ibook2.png"] forState:UIControlStateNormal]; // This will allow you to set title along background button image.
Upvotes: 0