- C/C++ code
uitextfield 不显示leftviewUITextField *fromField= [[UITextField alloc] initWithFrame:CGRectMake(43,8,215,30)]; fromField.delegate = self; fromField.backgroundColor= [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"input_field.png"]]; fromField.textAlignment = UITextAlignmentLeft; fromField.clearButtonMode = UITextFieldViewModeWhileEditing; fromField.returnKeyType = UIReturnKeyGo; fromField.placeholder=@"输入起点"; fromField.tag=indexPath.row; fromField.font=[UIFont fontWithName:@"Arial" size:12.0]; fromField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 45, 21)]; lbl.backgroundColor = [UIColor clearColor]; lbl.textColor = [UIColor lightGrayColor]; lbl.text = @"Start:"; UIButton *btnLeftImg = [UIButton buttonWithType:UIButtonTypeCustom]; [btnLeftImg setBackgroundImage:[UIImage imageNamed:@"hint_start_point.png"] forState:UIControlStateNormal]; btnLeftImg.frame = CGRectMake(0, 0, 9,9); fromField.leftView=lbl;
------解决方案--------------------
加上这个试试:
fromField.leftViewMode = UITextFieldViewModeAlways;