【发布时间】:2011-01-05 19:40:53
【问题描述】:
我是 Objective C 的新手。如何将此按钮的背景设置为图像(图像已经在 XCode 的资源文件夹中,“blue_button.png”)而不是 clearColor?另外,我更喜欢使用图像作为按钮的形状,而不是 UIButtonTypeRoundedRect。
btnClear = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
btnClear.frame = CGRectMake(115, 350, 90, 40);
[btnClear setTitle:@"Clear" forState:UIControlStateNormal];
btnClear.backgroundColor = [UIColor clearColor];
[btnClear addTarget:self action:@selector(clearAction:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnClear];
我知道如何在 Interface Builder 中执行此操作,但我更愿意学习在 XCode 中执行此操作。
【问题讨论】:
-
如果你使用 nib,你可以在 Interface Builder 中做到这一点
-
你应该接受一个答案,这对所有参与者都有好处......
标签: iphone objective-c xcode