我使用循環創建動態UIView
。但我不能創造UIView
根據的UILabel
大小好心幫我,我可以做進一步開展..需要你們的幫助。我會如何根據UILabel內容調整/設置UIView大小
for(NSString *item in myArray)
{
length = item.length;
self.custom=[[CustomView alloc]init];
self.custom.Label = [[UILabel alloc]initWithFrame:CGRectMake(40, yAxis, 100+item.length, 44)];
[self.custom setFrame:self.custom.Label.frame];
[self.custom sizeToFit];
yAxis=yAxis+50;
self.custom.tag=200+a;
a++;
[newViews addObject:self.custom];
length = item.length;
self.custom.Label = [[UILabel alloc]initWithFrame:CGRectMake(5,5,length+20,40)];
self.custom.button=[[UIButton alloc]initWithFrame:CGRectMake(85,10,12,10)];
[self.custom.Label setText:item];
// Tell the label to use an unlimited number of lines
[self.custom.Label setNumberOfLines:1];
[self.custom.Label sizeToFit];
self.custom.Label.textAlignment = UITextAlignmentCenter;
![this is image i have created uiview according the array values where uilabel more width than uiview so i need to set uiview according the uilabel][1]
UIImage *btnImage = [UIImage imageNamed:@"button_droparrow.png"];
[self.custom.button setImage:btnImage forState:UIControlStateNormal];
[self.custom.button addTarget:self
action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];
self.custom.button.tag=self.custom.button.tag+a;
self.custom.backgroundColor=[UIColor greenColor];
custom.Label.text=item;
custom.Label.backgroundColor = [UIColor yellowColor];
[self.custom addSubview:self.custom.button];
[self.custom addSubview:custom.Label];
// [self.custom addSubview:cv];
[self.view addSubview:self.custom];
}
我試過,但不起作用 –
轉貼你出把圖像 –
我的得分低於10,所以我可以鏈接圖像 –