我需要为textfield创建一个自定义占位符。我创建了自定义占位符方法,但没有得到如何在我的类中调用代码:
(void)drawPlaceholderInRect:(CGRect)rect {
// Set colour and font size of placeholder text
[[UIColor redColor] setFill];
[[UIColor colorWithRed:255.0 green:0.0 blue:0.0 alpha:0.7] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:5]];
}
主要.h 为自定义文本字段类创建对象
CustomUITextFieldPlaceholder *txtName;
但没有得到如何打电话
**txt_userinput.placeholder=?**
如果有多个textfield那么如何打电话请帮忙 提前谢谢
答案 0 :(得分:1)
您可以这样调用方法(在CustomUITextFieldPlaceholder类中):
[self drawPlaceholderInRect:aRect];
或者如果您想从CustomUITextFieldPlaceholder类外部调用:
[txtName drawPlaceholderInRect:aRect];
答案 1 :(得分:1)
制作CustomUITextFieldPlaceholder
对象然后你可以调用它 -
CustomUITextFieldPlaceholder *obj = [[CustomUITextFieldPlaceholder alloc]init];
[obj drawPlaceholderInRect:CGRectMake(x,y,width,height)];