2013-12-15 117 views
0

在我的应用程序中,我有一个地图视图,我想在地图上显示一个自定义按钮,如果放置按钮,它会显示,但是,如果我为图像放置背景图像,它不会被打印。按钮没有显示?

UIButton *customButton = [UIButton buttonWithType: UIButtonTypeCustom]; 
    [customButton setBackgroundImage:[UIImage imageNamed: 
@"Button_Default.png"] 
forState:UIControlStateNormal]; 
[customButton setBackgroundImage:[UIImage imageNamed: 
@"Button_Highlighted.png"] 
forState:UIControlStateHighlighted]; 
[customButton setFrame:CGRectMake(60, 100, 200, 40)]; 
[self.view addSubview:customButton]; 

我自己也尝试将最后一行的

[mapView addSubview:customButton]; 
+0

你能替换“[customButton setBackgroundImage:[UIImage imageNamed: @”Button_Highlighted.png“] forState:UIControlStateHighlighted];”与“[customButton setBackgroundImage:[UIImage imageNamed: @”Button_Highlighted.png“] forState:UIControlStateNormal];”并请让我知道..如果它的工作与否 – nikhilgohil11

+1

请确保您的资源文件夹中的资源,如“Button_Default.png”和“Button_Highlighted.png” –

+0

我相信我正在使用.png文件 – chandru

回答

0

你必须确保你已经添加到您的项目中的图像,可在资源文件夹&文件名使用的是在你的代码中不应该拼错(安静的人经常会使用关键字imagedNamed而不是imageNamed)。