Iphone 以编程方式在按钮上添加图像和文本
我想要一个图像和文本“查看详细信息” 在我的按钮(红色按钮)编程。。。 图像位于按钮的左侧,文本位于右侧Iphone 以编程方式在按钮上添加图像和文本,iphone,ios,Iphone,Ios,我想要一个图像和文本“查看详细信息” 在我的按钮(红色按钮)编程。。。 图像位于按钮的左侧,文本位于右侧 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 n
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];
我看到按钮,但没有,红色按钮…只有红色的角落 你制作一个按钮的图像,上面有红色和文本..并设置图像
USE buttonOBJ.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft
这是设置图像打开按钮的代码
[but1 setImage:[UIImage IMAGENAME:@“LeftBack.png”]forState:UIControlStateNormal]
//设置按钮上的图像。您可以发布创建按钮的代码吗?可能您将其作为RoundRectButton,请尝试使用CustomButton。由于内存问题,不建议使用imageNamed。更喜欢使用,而不是像这样从文件加载图像:
NSString *path = [[NSString alloc] initWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"fileName.png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[path release], path = nil;
看见
NSString *path = [[NSString alloc] initWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"fileName.png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[path release], path = nil;