Reputation: 140
I want an image and text "View Details" in my button(red color button) programmatically... image is on left side of button and text on right side..
UIImage *img = [UIImage imageNamed:@"image.png"];
[aButton setImage:img forState:UIControlStateNormal];
aButton.backgroundColor=[UIColor redColor];
//[img release]; i am not sure i release it or not
//[testBtn setTitleEdgeInsets:UIEdgeInsetsMake(70.0, -150.0, 5.0, 5.0)];
// what the above lines line work?
[aButton setTitle:@"View Details" forState:UIControlStateNormal];
I see the button but not, red color button...only red color corners...
Upvotes: 3
Views: 10543
Reputation: 1
NSString *path = [[NSString alloc] initWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"fileName.png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[path release], path = nil;
Upvotes: -1
Reputation: 129
Use of imageNamed is not recommended due to memory issues. prefer using instead loading the image from file like this:
NSString *path = [[NSString alloc] initWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"fileName.png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[path release], path = nil;
Upvotes: -1
Reputation: 1745
Could you post a code for creating a button? Maybe you have it as a RoundRectButton, try CustomButton instead.
Upvotes: 1
Reputation: 707
you make image of button having red color and text on it..and set the image on it...
This is the code for setting the image on button..
[but1 setImage:[UIImage imageNamed:@"LeftBack.png"] forState:UIControlStateNormal]
;//setting image on button.
Upvotes: 6
Reputation: 6323
USE buttonOBJ.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft
Upvotes: 1