我有一个 UITextField 的子类,因此我可以将 IndexPath 项添加到文本字段,如下所示:
@interface jnTextField : UITextField
@property (nonatomic, retain) NSIndexPath *indexPath;
@end
然后我将文本字段添加到 InterfaceBuilder 中的 UITableViewCell。但是,现在当我尝试设置文本颜色和字体时,它并没有像我使用标准 UITextField 那样设置。我还需要重写什么才能使其正常工作。我找不到任何可以解释我所缺少的东西的东西。我用来更改文本字体/颜色/文本的代码是我的 cellForRowAtIndexPath
方法:
cell.textField.text = @"add url";
cell.textField.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0];
cell.textField.textColor = [UIColor blueColor];
最佳答案
问题就在这里...您必须避免使用 UIKIT
类使用的相同属性名称。
cell.textField.text = @"add url";
cell.textField.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0];
cell.textField.textColor = [UIColor blueColor];
textField
是 UITableViewCell
类的一个属性,因此请在您的custom UITabelViewCell< 中更改
类似的类。custom UITextField 的
(jnTextField) 名称
cell.myCustomTextField.text = @"add url";
cell.myCustomTextField.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0];
cell.myCustomTextField.textColor = [UIColor blueColor];
要实现这一点,您可能必须像这样对单元格进行大小写
MYCustomCell *myCell = (MYCustomCell *)cell
myCell.myCustomTextField.text = @"add url";
myCell.myCustomTextField.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0];
myCell.myCustomTextField.textColor = [UIColor blueColor];
希望对你有所帮助。
关于ios - 子类化 UITextField 并设置文本字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25830432/