Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.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
Ios 带有图像和文本的UIButton不';行不通_Ios_Objective C_Uibutton - Fatal编程技术网

Ios 带有图像和文本的UIButton不';行不通

Ios 带有图像和文本的UIButton不';行不通,ios,objective-c,uibutton,Ios,Objective C,Uibutton,我在这里看到了两篇类似的帖子,但我找不到答案。 我正在尝试添加一个UIButton,该按钮设置为图像(仅背景色也很好) 我想在这张图片上添加文字 到目前为止,这是我的代码: labelSorry.text = @"לא נמצאו תוצאות.";//add text //add button. Request =[UIButton buttonWithType:UIButtonTypeCustom]; UIImage *requ

我在这里看到了两篇类似的帖子,但我找不到答案。 我正在尝试添加一个UIButton,该按钮设置为图像(仅背景色也很好) 我想在这张图片上添加文字

到目前为止,这是我的代码:

        labelSorry.text = @"לא נמצאו תוצאות.";//add text
        //add button.
        Request =[UIButton buttonWithType:UIButtonTypeCustom];
        UIImage *requestimg = [UIImage imageNamed:@"requestcontact_resize2.png"];
        Request.frame = CGRectMake(0.0, 120, 320.0, 30.0);
        Request.titleLabel.textAlignment = NSTextAlignmentRight;
       // Request.titleLabel.textColor = UIColorFromRGB(0xffffff);
        [Request setBackgroundImage:requestimg forState:UIControlStateNormal];
        Request.imageView.image = [UIImage imageNamed:@"requestcontact_resize2.png"];//see no image :( this is kidding me

      //  [Request setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
        UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0.0, 120, 320.0, 30.0)];///You can replace it with your own dimensions.
        label.textColor = UIColorFromRGB(0xffffff);
        label.text = @"בקש פרטי איש קשר";
        [Request addSubview:label];

        //[Request setBackgroundColor:UIColorFromRGB(0x704c9f)];
        Request.titleLabel.text = @"בקש פרטי איש קשר";
        [Request addTarget:self action:@selector(requestDetails) forControlEvents:UIControlEventTouchUpInside];
        [noResultsView addSubview:Request];
        [self.view addSubview:noResultsView];
我可以看到按钮的背景,但看不到按钮上的任何文字:( 也许有人能启发我

正如你们所看到的,我尝试过各种解决方案(我把它们放在评论中),但都不奏效

另外,我没有使用xib


任何帮助都将不胜感激。

您应该使用
[按钮设置图像:forState:][/code>和
[按钮设置标题:forState:][/code>。如果您想为按钮设置背景图像,您应该使用
[按钮设置背景图像:forState:][/code>。此外,如果需要,您可以更改图像和标题的位置,以便使用
[button setImageEdgeInsets:
[btn SetTitleedgeInSets:

但我确实使用了:[请求setBackgroundImage:requestimg forState:UIControlStateNormal];这里有问题吗?哦,我明白了,我在集合标题中没有使用“forState:)非常感谢:)