Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在UITableViewCell中设置textLabel的宽度_Iphone_Iphone Sdk 3.0_Ios_Ios4 - Fatal编程技术网

Iphone 在UITableViewCell中设置textLabel的宽度

Iphone 在UITableViewCell中设置textLabel的宽度,iphone,iphone-sdk-3.0,ios,ios4,Iphone,Iphone Sdk 3.0,Ios,Ios4,我有一个UITableViewCell,它有一个textLabel和一个UITextField作为子视图连接,如下所示: cell = [tableView dequeueReusableCellWithIdentifier:Value1CellIdentifier]; cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:Value1CellIdentifier] au

我有一个UITableViewCell,它有一个textLabel和一个UITextField作为子视图连接,如下所示:

cell = [tableView dequeueReusableCellWithIdentifier:Value1CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:Value1CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = @"Name";
UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
playerTextField.adjustsFontSizeToFitWidth = YES;
playerTextField.textColor = [UIColor blackColor];
playerTextField.placeholder = @"John Doe";
playerTextField.textAlignment = UITextAlignmentLeft;
[playerTextField setEnabled: YES];
[cell addSubview:playerTextField];
[playerTextField release];
文本标签占据了很大的空间。如何设置textLabel的宽度,以便UITableViewCell的其余部分获得提醒宽度


谢谢

文本标签是只读的。为什么不创建自己的并将其添加到单元格中?

简而言之,您可以使用在UITableViewCell类中执行的layoutSubviews方法设置UITableViewCell内UITextLabel的宽度。使用它可能需要您像前面提到的那样创建自己的自定义UITableViewCell类

以下链接中发布的答案提供了一个关于如何使用LayoutSubView的很好的示例:

该解决方案还概述了一种替代方法:

事实上,我可以将添加的子视图的位置设置为更“左”的位置,这样就可以了:)