【问题标题】:UITextView Shadow Not WorkingUITextView 阴影不工作
【发布时间】:2012-09-03 03:21:42
【问题描述】:

我正在尝试让 UITextView 的图层阴影在 UITableView 标头中工作。我有一个 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;

一切都在视图中正确显示。然而,影子并没有出现。我不知道这里出了什么问题。我什至尝试修改图层的框架,使其与评论字段的大小相同,更大且大小相同。

【问题讨论】:

  • 你的页眉高度是多少?是不是你的 newCommentField 的高度大于标题的高度?
  • 对不起,我不小心没有把它复制进去。它是 450。我认为 newCommentField 的高度较小。
  • 当iphone屏幕的全高是460时,你为什么要把标题​​高度设置为450?
  • 我只是希望用户能够看到 cmets 的顶部。如果用户是管理员并且我不希望管理员按钮位于屏幕下方,它也会更改为 460。
  • 对不起,我应该清楚,它在一个带有 cmets 的 tableview 上方。

标签: objective-c ios uitextview calayer shadow


【解决方案1】:

您没有为 newCommentField 设置背景颜色。 试试:

newCommentField.backgroundColor = [UIColor whiteColor];

【讨论】:

    【解决方案2】:

    您也可以这样做...创建一个与您的 textView 大小相同的视图(例如 bgView)并将该 textView 添加为 bgView 的子视图,该子视图将添加为您的标题视图的子视图。改为将阴影效果应用于 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];
    

    【讨论】:

    • @Neo 你知道为什么我们必须使用这个技巧来给 uitextview 添加阴影吗?谢谢。
    猜你喜欢
    • 2011-02-03
    • 2023-03-10
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    相关资源
    最近更新 更多