如何在自定义视图上获取文本字段

时间:2013-05-29 07:23:00

标签: cocoa-touch

我想在视图上显示文本字段。该视图的代码是

            if (indexPath.row==0) {
            UIView *viewshow=[[[UIView alloc]init]autorelease];
            viewshow.frame = CGRectMake(5, 60, 310, 230);
            viewshow.backgroundColor=[UIColor whiteColor];
            [cell addSubview:viewshow];

}

并通过此代码获取自定义文本字段

            if (indexPath.row==0) {
            UIView *viewshow=[[[UIView alloc]init]autorelease];
            viewshow.frame = CGRectMake(5, 60, 310, 230);
            viewshow.backgroundColor=[UIColor whiteColor];
            [cell addSubview:viewshow];
            UITextField* textField = [[UITextField alloc] initWithFrame:CGRectMake(5, 10, 30, 200)];
            textField.borderStyle = UITextBorderStyleRoundedRect;
            textField.placeholder = @"Enter the Text";
            textField.font = [UIFont fontWithName:@"Helvetica" size:12.0];
            textField.delegate = self;
            //cell.accessoryView = textField;
            [viewshow addSubview:textField];
         }

现在文本字段在垂直方向上而不是在视图中的水平方向上。现在我不明白我需要做什么来解决这个问题。 请帮忙.....

1 个答案:

答案 0 :(得分:0)

更改uitextfield的框架宽度和高度,即

 UITextField* textField = [[UITextField alloc] initWithFrame:CGRectMake(5, 10, 200, 30)];