【发布时间】:2011-04-17 23:04:46
【问题描述】:
我的 UITextView 只有 1 行文本。但是文本的下半部分被截断了,文本似乎被画得很低,或者文本视图似乎有一些高度,它需要大于我设置的 15。
UIFont *font = [UIFont fontWithName:@"Marker Felt" size:13];
CGSize size = CGSizeMake(310, 1000.f);
CGSize stringSize = [[messagesArray objectAtIndex:indexPath.row]
sizeWithFont:font constrainedToSize:size];
NSLog(@"txtView height: %d",(int)stringSize.height);
UITextView *txtview = [[UITextView alloc] initWithFrame:CGRectMake(5, 0,
310, (int)stringSize.height)];
txtview.autoresizesSubviews = NO;
[txtview setBackgroundColor:[UIColor blueColor]];
[txtview setFont:[UIFont fontWithName:@"Marker Felt" size:13]];
txtview.textColor = [UIColor whiteColor];
[txtview setOpaque:NO];
txtview.editable = NO;
txtview.text = [messagesArray objectAtIndex:indexPath.row];
[cell addSubview:txtview];
这一行
NSLog(@"txtView height: %d",(int)stringSize.height);
总是打印出 15 的值。字体大小为 13,所以我希望文本在 UITextView 中垂直居中放置,顶部和底部有 1 个像素。 15-13等
关于设置 UITextFields,我是否完全遗漏了什么?
非常感谢, 代码
【问题讨论】:
标签: iphone objective-c