IOS - 图像无法以编程方式显示

时间:2014-06-12 16:51:55

标签: ios objective-c uiimageview

我在代码中设置了图像,但图像不显示。当我在iPhone或模拟器上运行时,图像不显示。

我会为您提供代码。

以下是目前的代码:

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed:70.0f/255.0f
                                                green:111.0f/255.0f
                                                 blue:162.0f/255.0f
                                                alpha:1.0f];

    UIView *viewTopBar = [[UIView alloc] init];
    [self.view addSubview:viewTopBar];
    viewTopBar.backgroundColor = [UIColor colorWithRed:53.0f/255.0f
                                       green:85.0f/255.0f
                                        blue:127.0f/255.0f
                                       alpha:1.0f];
    viewTopBar.frame = CGRectMake(0,25,320,40);

    UIWebView *viewMusic = [[UIWebView alloc] init];
    [self.view addSubview:viewMusic];
    viewMusic.backgroundColor = [UIColor blackColor];
    viewMusic.frame = CGRectMake(0,65,320,270);
    viewMusic.mediaPlaybackRequiresUserAction=NO;
    viewMusic.allowsInlineMediaPlayback = YES;

    NSBundle* bundle = [NSBundle mainBundle];
    NSString* path = [bundle  pathForResource: @"index" ofType: @"html"];
    NSURL* url = [NSURL fileURLWithPath: path];
    NSURLRequest* req = [NSURLRequest requestWithURL: url];
    [viewMusic loadRequest: req];

    UIImageView *imageFBButton = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loginfb.gif"]];
    imageFBButton.frame = CGRectMake(43, 421, 234, 49);
    [self.view addSubview:imageFBButton];
}

@end

1 个答案:

答案 0 :(得分:0)

我尝试了你的代码。它没有任何问题加载图像。我相信它是一个糟糕的资源或失踪,因为“remus”说。附了屏幕截图。你可以在指定的位置看到谷歌图片。

enter image description here