不能像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];
}
}