我的目标是:
-
生成N个UILabels
UILabel*label0=[[UILabel alloc]init]
UILabel*label1=[[UILabel alloc]init]
UILabel*标签n=[[UILabel alloc]init];
-
使用addSubView将每个UILabel添加到视图中
为了生成UIN标签(如果我做得不对,请纠正我),我声明
NSMutableDictionay
在里面
viewcontroller.h
@property (strong,nonatomic)NSMutableDictionary *uiLabelsDictionary;
在viewcontroller中。m
self.uiLabelsDictionary = [[NSMutableDictionary alloc]init];
int yOffset = 40;
for(int i=0;i<10;i++)
{
yOffset = yOffset+40;
[self.uiLabelsDictionary setObject:[[UILabel alloc]initWithFrame:CGRectMake(10, yOffset, self.view.frame.size.width, self.view.frame.size.width)] forKey:[NSString stringWithFormat:@"label%d",i]];
}
NSLog(@"%@",self.uiLabelsDictionary);
我被困在下一步。如何将字典中存储的每个UILabel读取为UILabel并添加到视图?
字典输出
label0 = "<UILabel: 0x7f83dbd08ba0; frame = (10 80; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x608000090680>>";
label1 = "<UILabel: 0x7f83dbc0f7b0; frame = (10 120; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008e240>>";
label2 = "<UILabel: 0x7f83dbc15570; frame = (10 160; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008e4c0>>";
label3 = "<UILabel: 0x7f83dbc159a0; frame = (10 200; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008e5b0>>";
label4 = "<UILabel: 0x7f83dbc15c30; frame = (10 240; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008e790>>";
label5 = "<UILabel: 0x7f83dbc16040; frame = (10 280; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008ebf0>>";
label6 = "<UILabel: 0x7f83dbc162d0; frame = (10 320; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008ef10>>";
label7 = "<UILabel: 0x7f83dbc16560; frame = (10 360; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008e510>>";
label8 = "<UILabel: 0x7f83dbc167f0; frame = (10 400; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008ec40>>";
label9 = "<UILabel: 0x7f83dbc16a80; frame = (10 440; 320 320); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60800008f460>>";