Iphone UIButton背景颜色 [英] Iphone UIButton background color

查看:107
本文介绍了Iphone UIButton背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在循环中以编程方式创建了一些 UIButton 但是我在设置按钮的背景颜色方面遇到了一些问题。

I'm creating some UIButtons programmatically in a loop but I'm having some problem with setting the background color of the button.

按钮的颜色始终显示为白色。
但是我只使用backgroundcolor中的2种颜色。
例如:红色:255绿色:0蓝色:200

The color of the button always shows up as white. But works fine with I'm only using 2 colors in the backgroundcolor. Eg : red : 255 green:0 blue :200

这是我用来添加按钮的代码。

Here is the code I'm using to add the button.

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(80, 20 + (i*75), 200, 75);
    button.layer.cornerRadius = 10;
    button.layer.borderWidth = 1;
    [button setTitle:@"saf" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(moveLocation:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundColor:[UIColor colorWithRed:255 green:180 blue:200 alpha:1]];
    button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [scrollView addSubview:button];


推荐答案

我相信你正在构建你的UIColor错误。

I believe you are building your UIColor wrong.

试试这个:

[button setBackgroundColor:[UIColor colorWithRed:(255/255.0) green:(180/255.0) blue:(200/255.0) alpha:1]];

这篇关于Iphone UIButton背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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