文本字段背景颜色不会更改它与UI文本边框样式圆角矩形

时间:2012-05-11 01:55:58

标签: objective-c ios ios5 uitextfield ios4

我正在尝试更改IUTextField中的背景颜色,但如果我没有设置UITextBorderStyleRoundedRect,我只会成功。

theTextField.borderStyle=UITextBorderStyleNone;

我试图在IBuilder和

中做到这一点
theTextField.backgroundColor=[UIColor colorWithRed:m_r green:m_g blue:m_b alpha:1.0];

IOS 4.X发生在IOS 5.X上 知道可以做什么吗?

1 个答案:

答案 0 :(得分:1)

我已经完成了一个示例代码,对我来说,所有iOS版本的工作都很好> = 3.2

这是代码

- (IBAction)button:(id)sender {

  if ([[textField backgroundColor] isEqual:[UIColor greenColor]]) {

    [textField setBackgroundColor:[UIColor yellowColor]];
  }
  else {

    [textField setBackgroundColor:[UIColor greenColor]];

  }
}

此处 textField 是我的xib文件中提供的IBOutlet连接。

还添加了一个连接了此操作方法的UIButton。它对我来说很完美..

我建议您尝试使用此代码的示例。