Objective c 在XCode中将文本标签更改为图像

Objective c 在XCode中将文本标签更改为图像,objective-c,uilabel,Objective C,Uilabel,我正在开发的iOS应用程序的XCode项目中有以下代码: testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 320, 480)]; UIFont *Font = [UIFont fontWithName:@"Arial" size:40]; [testLabel setFont:Font]; [testLabel setTextAlignment:UITextAlignmentCenter];

我正在开发的iOS应用程序的XCode项目中有以下代码:

    testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
    UIFont *Font = [UIFont fontWithName:@"Arial" size:40];
    [testLabel setFont:Font];
    [testLabel setTextAlignment:UITextAlignmentCenter];
    [testLabel setTextColor:[UIColor colorWithRed:(float) 55/255 green:(float) 41/255 blue:(float) 133/255 alpha:1.0]];
    testLabel.text = @"Here We Go";

我想在那个地方放一张图片,而不是文字。我需要用什么来替换此代码?

或者制作一个图像并将其放入
UIImageView
中,或者制作一个
UIView
子类,在其中您将在
drawRect
方法中绘制文本。 在第二种情况下,在
drawRect
中执行以下操作:

[self.yourStringProperty drawAtPoint:CGPointMake(100,150) withFont:[UIFont systemFontOfSize:14.0]]; 
or
[self.yourStringProperty drawInRect:rect withFont:[UIFont systemFontOfSize:14.0]]; 

此外,还可以考虑可用宽度、最小尺寸、换行符等,寻找这些功能的详细说明。

我上面的答案是第二部分的最佳答案:使用UIView,并根据需要将标签或UIImageView放入其中。以下是图像的外观:

UIView *container = [[UIView alloc] initWithFrame:CGRectMake(<<your image frame here>>)];
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]];
image.frame = CGRectMake(<<your image frame here>>);
[container addSubview:image];
[self.view addSubview:container];
UIView*container=[[UIView alloc]initWithFrame:CGRectMake();
UIImageView*image=[[UIImageView alloc]initWithImage:[UIImageName:@“yourImage.png”];
image.frame=CGRectMake();
[容器添加子视图:图像];
[self.view addSubview:container];

谢谢。我更想知道确切的代码是什么样子的,不客气。我补充了一点解释。如果您搜索
draw..
方法,您应该会找到很多示例。