Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 以编程方式在按钮上添加图像和文本_Iphone_Ios - Fatal编程技术网

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;