简体   繁体   English

UITextView阴影不起作用

[英]UITextView Shadow Not Working

I am trying to get a UITextView's layer's shadow to work in a UITableView header. 我正在尝试获取UITextView图层的阴影以在UITableView标头中工作。 I have a UIView that I am formatting everything in, and then setting the headerview equal to it. 我有一个要格式化所有内容的UIView,然后将headerview设置为其相等。

UIView * view = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.tableView.frame.size.width, 450);
UIColor * baseColor = [[UIColor alloc] initWithRed: 45/255.0
                                             green: 100/255.0
                                              blue: 150/255.0
                                             alpha: 1.0];

view.backgroundColor = baseColor;
...
UITextView * newCommentField = [[UITextView alloc] initWithFrame:CGRectMake(20, 230, 270,   120)];
newCommentField.text = @"New Comment";
newCommentField.tag = 3;
newCommentField.layer.shadowOffset = CGSizeMake(0, 3);
newCommentField.layer.shadowRadius = 5.0;
newCommentField.layer.shadowColor = [UIColor blackColor].CGColor;
newCommentField.layer.shadowOpacity = 0.8;
[view addSubview:newCommentField];
...
self.tableView.tableHeaderView = view;

Everything shows up properly in the view. 一切都正确显示在视图中。 However, the shadow is not appearing. 但是,没有出现阴影。 I don't know what is going wrong here. 我不知道这里出了什么问题。 I have even tried modifying the layer's frame and making it the size of the comment field, bigger and the same size. 我什至尝试修改图层的框架并使它的注释字段的大小更大,相同。

You're not setting background color for newCommentField. 您没有为newCommentField设置背景色。 Try: 尝试:

newCommentField.backgroundColor = [UIColor whiteColor];

You can do it this way also... Create a view (eg. bgView) of same size as your textView and add that textView as a subView of bgView, which will be added as subView of you header view. 您也可以通过这种方式进行操作...创建一个与textView大小相同的视图(例如bgView),并将该textView添加为bgView的子视图,它将作为标题视图的subView添加。 Apply the shadow effect to the bgView instead. 而是将阴影效果应用于bgView。

UIView *bgView=[[UIView alloc]initWithFrame:CGRectMake(20, 230, 270,   120)];
bgView.backgroundColor=[UIColor whiteColor];
bgView.layer.shadowOffset = CGSizeMake(0, 3);
bgView.layer.shadowRadius = 5.0;
bgView.layer.shadowColor = [UIColor blackColor].CGColor;
bgView.layer.shadowOpacity = 0.8;

[bgView addSubview:newCommentField];

[view addSubview:bgView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM