我有兩個textViews的數據被動態填充。一旦數據填充後,我想調整textview的高度,以便我看不到垂直滾動或文本被剪切。我想以編程方式執行此任務。如何自動擴展UITextview基於在ios中顯示字符串
tViewhobbies=[[UITextView alloc]initWithFrame:CGRectMake(10,
330,
300,
strSize.height+20)];
tViewhobbies.backgroundColor=[UIColor clearColor];
tViewhobbies.layer.cornerRadius=5;
[tViewhobbies setUserInteractionEnabled:NO];
tViewhobbies.font=[UIFont systemFontOfSize:12.0];
tViewhobbies.backgroundColor=[UIColor colorWithRed:0.662745
green:0.662745
blue:0.662745
alpha:0.5];
tViewhobbies.delegate=self;
tViewhobbies.scrollEnabled=YES;
[scrollView addSubview:tViewhobbies];
lblInterests = [[UILabel alloc]initWithFrame:CGRectMake(10,
410,
300,
strSize.height+0)];
[email protected]"Interests";
lblInterests.font=[UIFont systemFontOfSize:16.0];
lblInterests.textColor=[UIColor colorWithRed:153.0f/255.0f
green:153.0f/255.0f
blue:153.0f/255.0f
alpha:1];
[scrollView addSubview:lblInterests];
tViewInterests=[[UITextView alloc]initWithFrame:CGRectMake(10,
430,
300,
strSize.height+30)];
tViewInterests.backgroundColor=[UIColor clearColor];
tViewInterests.layer.cornerRadius=5;
[tViewInterests setUserInteractionEnabled:NO];
tViewInterests.font=[UIFont systemFontOfSize:14.0];
tViewInterests.backgroundColor=[UIColor colorWithRed:0.662745
green:0.662745
blue:0.662745
alpha:0.5];
tViewInterests.delegate=self;
tViewInterests.scrollEnabled=YES;
[scrollView addSubview:tViewInterests];
你有沒有試着去'[txtvw sizeToFit]'? –