不能像label那样设置,需要layer层设置
UITextView *chuanYiTextView = [UITextView new];
chuanYiTextView.backgroundColor = [UIColor clearColor];
chuanYiTextView.editable = NO;
chuanYiTextView.textColor = [UIColor whiteColor];
chuanYiTextView.font = [UIFont systemFontOfSize:11];
chuanYiTextView.layer.shadowColor = [UIColor grayColor].CGColor;//阴影颜色
chuanYiTextView.layer.shadowOffset = CGSizeMake(0.5, 1);//偏移距离
chuanYiTextView.layer.shadowOpacity = 1;//不透明度
chuanYiTextView.layer.shadowRadius = 0.8;//半径
chuanYiTextView.scrollEnabled = YES;
[self addSubview:chuanYiTextView];
第二个问题
- (void)contentSizeToFitOf:(UITextView *)textView {
if([textView.text length]>0) {
CGSize contentSize = textView.contentSize;
UIEdgeInsets offset;
CGSize newSize = contentSize;
if(contentSize.height <= textView.frame.size.height) {
CGFloat offsetY = (textView.frame.size.height - contentSize.height)/2;
offset = UIEdgeInsetsMake(offsetY, 0, 0, 0);
}
else {
newSize = textView.frame.size;
offset = UIEdgeInsetsZero;
CGFloat fontSize = 18;
while (contentSize.height > textView.frame.size.height) {
[textView setFont:[UIFont fontWithName:@"Helvetica Neue" size:fontSize--]];
contentSize = textView.contentSize;
}
newSize = contentSize;
}
[textView setContentSize:newSize];
[textView setContentInset:offset];
}
}

本文介绍如何使用 iOS 中的 UITextView 进行自定义样式设置,包括背景颜色、字体大小、颜色及阴影效果等,并提供自动调整文本视图大小以适应内容的方法。
5820

被折叠的 条评论
为什么被折叠?



