各位大虾,请问怎样修改button的底色?

kangqijun 2010-10-09 06:19:15
一般将一个按钮按下时,按钮变为蓝色,怎样修改才能使蓝色变为其它颜色?
能否给出具体代码,谢谢!
...全文
189 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
kangqijun 2010-10-13
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 cloudhsu 的回复:]

引用 10 楼 kangqijun 的回复:
成功了,在你的代码下在加了一句[self.view addSubview:button];

呃....我一直以为这个您会自己加.....
这是加上button的或其他东西的基本用法.....汗
[/Quote]
呵呵,我刚入门,懂得太少了。
向前辈学习!
kangqijun 2010-10-12
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 qinqijing_123 的回复:]

要修改很简单啊,修改RGB啊...
[/Quote]
RGB是何物?
云瑀 2010-10-12
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 kangqijun 的回复:]
成功了,在你的代码下在加了一句[self.view addSubview:button];
[/Quote]
呃....我一直以为这个您会自己加.....
这是加上button的或其他东西的基本用法.....汗
Rainqin123 2010-10-12
  • 打赏
  • 举报
回复
要修改很简单啊,修改RGB啊...
kangqijun 2010-10-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cloudhsu 的回复:]

C/C++ code
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 233.0f)];
[button setBackgroundImage:[[UIImage imageNamed:@"test.png"] stretchableImageWithLeftCapWidth:1……
[/Quote]
成功了,在你的代码下在加了一句[self.view addSubview:button];
kangqijun 2010-10-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cloudhsu 的回复:]

C/C++ code
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 233.0f)];
[button setBackgroundImage:[[UIImage imageNamed:@"test.png"] stretchableImageWithLeftCapWidth:1……
[/Quote]
能否给个小例子吗?本人愚笨!
kangqijun 2010-10-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 windows_star 的回复:]

或者给按钮得touchupinside添加一个action

然后在action里面修改按钮的背景

button.backgroundcolor = [UIColor yourcolor];
[/Quote]
您的这个方法行不通啊!
kangqijun 2010-10-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 cloudhsu 的回复:]

引用 5 楼 kangqijun 的回复:
引用 2 楼 cloudhsu 的回复:

C/C++ code
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 233.0f)];
[button setBackgroundImage:[[UIImage imageNamed……
[/Quote]
我搞了半天,还是没实现啊,哥啊!
这到底是为什么啊!
云瑀 2010-10-11
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 kangqijun 的回复:]
引用 2 楼 cloudhsu 的回复:

C/C++ code
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 233.0f)];
[button setBackgroundImage:[[UIImage imageNamed:@"test.png"] stretchabl……
[/Quote]
這已經是例子了........汗....
windows_star 2010-10-09
  • 打赏
  • 举报
回复
或者给按钮得touchupinside添加一个action

然后在action里面修改按钮的背景

button.backgroundcolor = [UIColor yourcolor];
云瑀 2010-10-09
  • 打赏
  • 举报
回复
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 233.0f)];
[button setBackgroundImage:[[UIImage imageNamed:@"test.png"] stretchableImageWithLeftCapWidth:110.0 topCapHeight:0.0] forState:UIControlStateNormal];
[button setBackgroundImage:[[UIImage imageNamed:@"test2.png"] stretchableImageWithLeftCapWidth:110.0 topCapHeight:0.0] forState:UIControlStateHighlighted];

利用换背景把button背景图换掉
UIControlStateHighlighted是按下button后显示的图片.....
windows_star 2010-10-09
  • 打赏
  • 举报
回复
这类问题,如果没有提供api,就继承uibutton, 然后重新写drawrect函数。

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧