Xcode:仅为默认状态设置按钮上的图像,未选中 [英] Xcode: set image on button only for default state, not also selected

查看:55
本文介绍了Xcode:仅为默认状态设置按钮上的图像,未选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Xcode 和 iPhone 编程的新手.我有一个简单的问题困扰着我.我想在按钮上设置一个图像,因为它是默认状态.所以我选择按钮,并在显示属性检查器"选项卡中,选择状态配置"作为默认值,然后在图像"下拉列表中找到所需的图像...

I am new to Xcode and iPhone programming in general.. I have a simple problem thats bugging me.. I want to set an image on a button, for it's default state. So I select the button, and in the "Show the attributes inspector"-tab, I select "state config" to be default, then I find the desired image in "image"-drop down list...

问题:

我将状态配置"更改为选中,图像仍然打开.我需要图像仅在默认状态下打开.如果我想在默认状态和选定状态下标题文本的字体大小不同,我会遇到同样的问题.我正在使用 Xcode 4.6 并为 iOS 6.1 编写代码.

I change the "state config" to selected, and the image is still on. I need the image to only be on in default state. I have same problem if i want different font size of the title text in default- and selected-state. I'm using Xcode 4.6 and writing for iOS 6.1.

推荐答案

有两种方法.

第一种方式,以编程方式:

First way, programmatically:

[button setBackgroundImage:buttonimg forState:UIControlStateSelected];
[button setBackgroundImage:buttonimg forState:UIControlStateNormal];
[button setBackgroundImage:buttonimg forState:UIControlStateHighlighted];

第二种方式,使用IB Builder:

Second way, using IB Builder:

喜欢img:

您可以选择状态配置.根据配置,您可以在名为Image"的部分下设置图像.

You have a option of selecting a state config. Based on the config, you can set the image under the section called "Image".

希望这有帮助...

这篇关于Xcode:仅为默认状态设置按钮上的图像,未选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆