made an object, MyTextBoxCreator. i need to make lots of text boxes dynamically. i want to be able to pass in a frame to the method.
.h file
-(UITextField *) standardTextField: (CGRect *) myRec;
.m file
-(UITextField *) standardTextField: (CGRect *) myRect
{
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)];
UITextField *myTextField = [[UITextField alloc] initWithFrame:myRect];
myTextField.font = [UIFont fontWithName:textFieldFont size:textFieldFontSize];
myTextField.borderStyle = UITextBorderStyleLine;
myTextField.backgroundColor = [UIColor whiteColor];
myTextField.textColor = [UIColor textFieldTextColor];
myTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myTextField.layer.borderColor = [[UIColor textfieldBorderColor]CGColor];
myTextField.layer.borderWidth = 1.0f;
myTextField.leftView = paddingView;
myTextField.leftViewMode = UITextFieldViewModeAlways;
myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
return myTextField;
}
when i try to create the textfield with myRect for the CGRect, i get the error:
Sending 'CGRect *' (aka 'struct CGRect *') to parameter of incompatible type 'CGRect" (aka "struct CGRect')
i don’t understand whats wrong with passing in the CGRect…
Don’t pass a pointer to the
CGRect, just pass the structure itself.Note that it’s a structure, not an actual object.
Though, if you need to pass in a pointer to the struct, you can dereference it: