【发布时间】:2014-05-12 13:56:21
【问题描述】:
我没有在我的应用程序中使用滚动视图,并且对其属性也没有什么经验。我希望滚动视图包含一个小的UITextView,当用户点击添加按钮时,它将在前一个下方创建一个新的UITextView,并在那里输入新数据。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:[[UIScreen mainScreen] bounds]];
if (self) {
self.backgroundColor = [UIColor clearColor];
UIScrollView *tempScroll = [UIScrollView new];
self.logScroll = tempScroll;
self.logScroll.frame = CGRectMake(0, 120, 320, 390);
self.logScroll.contentSize= CGSizeMake(320,1280);
self.logScroll.layer.cornerRadius = 10.0f;
[self.logScroll showsVerticalScrollIndicator];
self.logScroll.backgroundColor = [UIColor whiteColor];
[self addSubview:tempScroll];
UIButton *addWorkoutButton = [UIButton buttonWithType:UIButtonTypeSystem];
addWorkoutButton.frame = CGRectMake(100, 0, 100, 30);
[addWorkoutButton setTitle:@"Add Workout" forState:UIControlStateNormal];
[addWorkoutButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[addWorkoutButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
[addWorkoutButton addTarget:self action:@selector(addNewTextViewToLogScroll:) forControlEvents:UIControlEventTouchUpInside];
[tempScroll addSubview:addWorkoutButton];
[tempScroll setNeedsDisplay];
}
return self;
}
- (void) addNewTextViewToLogScroll:(id)sender {
UITextField *newField = [[UITextField alloc]initWithFrame:CGRectMake(10,20,300,60)];
newField.backgroundColor = [UIColor colorWithWhite:0.940 alpha:1.0];
[logScroll addSubview:newField];
[logScroll setNeedsDisplay];
}
这是我目前所拥有的。现在我的问题是将新的UITextField 添加到滚动视图上的先前UITextView 之下。我如何让它添加到前面的下面
【问题讨论】:
-
您是否尝试过任何尝试?您是否阅读了文档或进行了任何搜索?您的问题没有表现出任何努力,而且过于宽泛。
-
是的,我已经添加了到目前为止的代码。 @rmmaddy
-
增加新文本字段框架的
y值。
标签: ios view uiscrollview uitextview