Ios 向UIscrollView动态添加新的UITextView
我没有在我的应用程序中使用滚动视图,并且对其属性几乎没有经验。我希望滚动视图包含一个小的Ios 向UIscrollView动态添加新的UITextView,ios,view,uiscrollview,uitextview,Ios,View,Uiscrollview,Uitextview,我没有在我的应用程序中使用滚动视图,并且对其属性几乎没有经验。我希望滚动视图包含一个小的UITextView,当用户点击添加按钮时,它将在前一个视图的正下方创建一个新的UITextView,并在那里输入新数据 - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:[[UIScreen mainScreen] bounds]]; if (self) { self.backgroundColor
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];
}
这就是我目前所拥有的。现在我的问题是在scrollview上先前的
UITextView
下面添加新的UITextField
。如何将其添加到上一个1的下方。创建文本字段
UITextField *newField = [[UITextField alloc]initWithFrame:CGRectMake(10,10,100,20)];
[yourScrollView setNeedsDisplay];
二,。将其添加到滚动视图中
[yourScrollView addSubview:newField];
3.刷新滚动视图的内容以显示新添加的文本字段
UITextField *newField = [[UITextField alloc]initWithFrame:CGRectMake(10,10,100,20)];
[yourScrollView setNeedsDisplay];
你有试过什么吗?你看过文件了吗,或者做过搜索吗?你的问题没有表现出任何努力,而且太宽泛了。是的,我已经添加了到目前为止的代码@rmmaddy增加新文本字段框架的
y
值。