Reputation: 83
I'm currently developing my first app, and I'm having a bit of an issue. I've made a custom button using JavaScript, then by screenshotting I've been able to import it as a custom button into XCode. However, I'm unable to put any text on it; anything I do appears to the side. I've searched through other threads and found the following code:
[_Button setTitle:@"ClickMe!" forState:UIControlStateNormal];
However, this just causes text to appear to the side of the custom button. Can anyone help me fix this?
EDIT: Here's my code in ViewController.h:
@property (strong, nonatomic) IBOutlet UIButton * RoadMap;
@property (weak, nonatomic) IBOutlet UILabel * myLabel;
And.. relevant code in ViewController.m
_myLabel.text=@"Road Map";
[_RoadMap removeFromSuperView];
[_RoadMap setBackgroundImage:[UIImage imageNamed:@"button.PNG"] forState:UIControlStateNormal];
Upvotes: 1
Views: 24
Reputation:
Looks like you using foreground image for button.
Try to use background image:
[_Button setBackgroundImage:[UIImage imageNamed:@"imageName"] forState:UIControlStateNormal];
In this case text will rendered above the image.
Update:
Just remove these two lines of code:
_myLabel.text=@"Road Map";
[_RoadMap removeFromSuperView];
And add this line:
[_RoadMap setTitle:@"RoadMap" forState:UIControlStateNormal];
Upvotes: 1