在iphone中以编程方式添加uibutton中的图像

时间:2011-01-25 05:47:48

标签: iphone cocoa-touch

我是iphone开发的新手。我试图用图像开发按钮(当我点击按钮时图像会显示)这个应用程序将像iphone中的programmaticaly一样开发。

任何人都可以帮我解决我的问题。

提前谢谢。

1 个答案:

答案 0 :(得分:5)

这样做:


UIImage *newButtonImage = [UIImage imageNamed:@"imageInMyProject.png"];
//Create image object from bundle. Name must include filetype; is case sensetive.

[myButton setImage:newButtonImage forState:UIControlStateNormal];
//Set the image for the button when it is in it's default state.

这种做事方式很棒,因为您可以根据需要将图像设置为不同的显示方式。可以在此处找到不同的UIControlStates:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIControl_Class/Reference/Reference.html#//apple_ref/c/tdef/UIControlState

快乐编码:)