2012-03-23 134 views
2

目标C对我来说是新的。如何更改表格视图中文本字段的字体?这是我现在有代码:如何在表格视图中更改文本字段的字体

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

if (indexPath.section==0) 
    { 
     UITextField *textField= [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 205, 21)]; 
     textField.placeholder = @" "; 
      //textField.text = [listOfItems objectAtIndex:indexPath.row]; 
     textField.tag = indexPath.row; 
      //textField.textLabel.font = [UIFont fontWithName:@"Helvetica" size:12]; 
      //textField.placeholder = [TeamBDict objectAtIndex:textField.tag]; 
     textField.delegate = self; 
     cell.accessoryView = textField; 
     [textField release]; 
    } 
+0

的注释行也将这样做。 'textField.textLabel.font = [UIFont fontWithName:@“Helvetica”size:12];' – 2012-03-23 15:18:15

+1

请阅读stackoverflow的FAQ。 – Danra 2012-03-23 15:18:21

回答

3
textField.font = [UIFont fontWithName:@"Helvetica" size:12]; 

由于每documentation你应该阅读。

+0

我正在尝试“textlabel.textfield.font”.. – 2012-03-23 15:23:53

+0

没有'UITextField'的textLabel属性(Xcode可能告诉你),只有一个'UITableViewCell'。 – 2012-03-23 15:24:55

+0

感谢Evan的帮助 – 2012-03-23 15:31:43

0

更改文本字段的字体是设置它的font属性一样简单:

textField.font = [UIFont fontWithName:@"Courier" size:16.0]; 

您所提供的代码需要一些工作,虽然。 -tableView:cellForRowAtIndexPath:`预计会返回一个表格单元格。您需要阅读Table View Programming Guide以了解如何做到这一点。

0

雨燕3.0的iOS 10.x的答案

textField.font = UIFont(name: "Helvetica", size: 16) 
0
textfield.font = UIFont(name:"whatever u choose language type here",size:17) 
相关问题