-2
我是iPhone開發者的初學者。我想給textView上的動態寬度和高度,我已經在下面的代碼中使用了寬度和高度,當我在textview中寫入時,它將在視圖上向上,而不是寫入幀的實際大小。texView動態高度和寬度
我用
-(void)viewDidLoad
{
writTxtView = [[UIView alloc]initWithFrame:CGRectMake(100,90,50,40)];
[writTxtView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:writTxtView];
writeTxt = [[UITextView alloc]initWithFrame:CGRectMake(0,0,50,40)];
[writeTxt setBackgroundColor:[UIColor clearColor]];
[writeTxt setFont:[UIFont systemFontOfSize:12]];
[writeTxt setTextColor:[UIColor whiteColor]];
[writeTxt setDelegate:self];
[writeTxt setHidden:YES];
[writTxtView addSubview:writeTxt];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
tooDoneBar.hidden = NO;
if([text isEqualToString:@"\n"]) {
//[textView resignFirstResponder];
return YES;
}
textView.backgroundColor = [UIColor greenColor];
CGFloat maxHeight = 312.0f;
NSLog(@"MytextViewframe :%@",NSStringFromCGRect(textView.frame));
CGFloat fixedWidth = writTxtView.frame.origin.x;
NSLog(@"FixedWidth :%f",fixedWidth);
CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = textView.frame;
NSLog(@"newFrame :%@",NSStringFromCGRect(textView.frame));
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), fminf(newSize.height, maxHeight));
textView.frame = newFrame;
NSLog(@"OthernewFrame :%@",NSStringFromCGRect(textView.frame));
writTxtView.frame = newFrame;
return YES;
}
所以,給適用於我的代碼
謝謝你......