3

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...

GauravBoss
  • 140
  • 2
  • 4
  • 13

5 Answers5

6

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.

Gopesh Gupta
  • 707
  • 8
  • 19
1
USE buttonOBJ.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft
Narayana Rao Routhu
  • 6,303
  • 27
  • 42
1

Could you post a code for creating a button? Maybe you have it as a RoundRectButton, try CustomButton instead.

Ertai
  • 1,735
  • 2
  • 23
  • 29
-1

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;
Sheni
  • 129
  • 8
-1
NSString *path = [[NSString alloc]  initWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"fileName.png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[path release], path = nil;
Dan
  • 10,531
  • 2
  • 36
  • 55
ranjit
  • 1