我希望此代碼生成5次標籤測試,但它會生成5個標籤,其中4個標籤只有2個點,最後一個具有正確的字符串測試。ios動態創建uilabels不返回預期的結果
- (void)viewDidLoad
{
int n = 5;
int yValue = 100;
for(int i = 0; i < n; i++){
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0, yValue, 80, 44)];
label.text = @"text"; //etc...
[self.view addSubview:label];
yValue += 20;
}
[super viewDidLoad];
}
我在做什麼錯?
標籤的高度 - 44.標籤間的差距 - 20,小於44.設置'yValue + = 44',我想你會看到莫拉比2點。我想點 - 't'字母的頂部。:) –
哈哈,我是個白癡。謝謝。 – user1108720
接受我的答案plz。 –