我有一個簡單的textView
誰動態填充了數據。我想調整textview的高度,一旦填充數據,以便我看不到垂直滾動或文本被剪輯。我想以編程方式執行此任務。我有一個標籤,應該被放置在文本視圖的高度低於20像素像「有趣」。我試圖做代碼。但我有一些問題,如對齊問題。如果我可以運行該程序,輸出將顯示像這樣。如何在ios中動態調整基於字符串的UITextview高度
這是我Program.please幫我任何人。
lblHobbies = [[UILabel alloc]initWithFrame:CGRectMake(10, 310, 300, 20)];
[email protected]"Hobbies";
lblHobbies.font=[UIFont systemFontOfSize:16.0];
lblHobbies.textColor=[UIColor colorWithRed:153.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1];
[scrollView addSubview:lblHobbies];
lblInterests = [[UILabel alloc]initWithFrame:CGRectMake(10, 420, 300, strSize.height+30)];
[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];
NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14]};
CGRect rect =
[tViewhobbies.text boundingRectWithSize:CGSizeMake(300, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil];
tViewhobbies=[[UITextView alloc]init];
tViewhobbies.frame=CGRectMake(10, 330,300, rect.size.height);
[tViewhobbies setUserInteractionEnabled:NO];
tViewhobbies.backgroundColor=[UIColor colorWithRed:0.662745 green:0.662745 blue:0.662745 alpha:0.5];
tViewhobbies.delegate=self;
[scrollView addSubview:tViewhobbies];
NSDictionary *attributes1 = @{NSFontAttributeName: [UIFont systemFontOfSize:14]};
CGRect rect1 =
[tViewInterests.text boundingRectWithSize:CGSizeMake(300, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes1
context:nil];
tViewInterests=[[UITextView alloc]init];
tViewInterests.frame=CGRectMake(10, 450, 300, rect1.size.height);
[tViewInterests setUserInteractionEnabled:NO];
tViewInterests.backgroundColor=[UIColor colorWithRed:0.662745 green:0.662745 blue:0.662745 alpha:0.5];
tViewInterests.delegate=self;
[scrollView addSubview:tViewInterests];
這兩個支持看到這個http://stackoverflow.com/questions/19215199/dynamically-size-uitableviewcell-according-to-uilabel-with-paragraph-spacing/19217965#19217965支持iOS6和iOS7 –
乾草看到我的答案希望你有一些想法,只是使用你的代碼insted你的:) :) –