And*_*rew 1 iphone cocoa-touch runtime objective-c
假设我在屏幕上有一个标签和一个按钮.当用户按下按钮时,它会在已经存在的标签下方生成新标签,并且可以无限次地执行此操作.
我不需要代码来建立新职位.我只是想知道如何添加新标签?我可以用一堆与它相关的变量做同样的事情,比如说创建一些NSStrings吗?
您需要做的是创建一个UILabel视图,并以编程方式将其作为子视图添加到当前视图中.
NSMutableArray *labelArray; /* assumes it has your other labels */
UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(/* your frame to locate the label */)];
newLabel.text = @"whatever";
[self.view insertSubview:newLabel below:[labelArray lastObject]];
[labelArray addObject:newLabel];
[newLabel release];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
136 次 |
最近记录: |