Iphone UIButton背景颜色

Tim*_*Tim 5 iphone objective-c background-color uibutton

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

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

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

    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];
Run Code Online (Sandbox Code Playgroud)

Jak*_*sey 20

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

试试这个:

[button setBackgroundColor:[UIColor colorWithRed:(255/255.0) green:(180/255.0) blue:(200/255.0) alpha:1]];
Run Code Online (Sandbox Code Playgroud)

  • +1绝对.同意.组件为0-1而不是0-255. (2认同)