2013年9月11日 星期三

UITextField 設定 游標的 顏色 set color

step1.

宣告一個 UITextField *bmiTextField;

加入


 bmiTextField.delegate = self;



step2.

設定事件

- (void)textFieldDidEndEditing:(UITextField *)textField
{

      //確定text裡面有值
        if(textField.layer.borderWidth)
        {
            textField.layer.borderWidth = 0;
            textField.backgroundColor = [UIUtility greenColor];
            textField.textColor = [UIColor whiteColor];
           //設定游標顏色
            [[textField valueForKey:@"textInputTraits"] setValue:[UIColor whiteColor] forKey:@"insertionPointColor"];
        }

       
    }
//確定text裡面沒有值
    else
    {
        [[textField valueForKey:@"textInputTraits"] setValue:[UIColor blueColor] forKey:@"insertionPointColor"];
        textField.layer.borderWidth = 0.5;
        textField.backgroundColor = [UIColor whiteColor];
        textField.textColor = [UIColor blackColor];
    }
}

0 意見:

張貼留言