【问题标题】:UIRectFill is not working in iOS 7UIRectFill 在 iOS 7 中不起作用
【发布时间】:2013-10-19 07:18:33
【问题描述】:

尝试在 UITableViewCell 中绘制一个矩形

//Works with iOS6 and earlier but NOT with ( iOS7 )

 - (void)drawRect:(CGRect)rect {
    // Creating a black border
    [[UIColor blackColor] setFill];
    UIRectFill(CGRectMake(10, 5, 40, 43));

    // Filling with rig color
    [[UIColor colorWithRed:r green:g blue:b alpha:a] setFill];
    UIRectFill(CGRectMake(11, 6, 38, 41));
}

有人知道为什么这在 iOS 7 中不起作用,而在 iOS 6 中起作用吗?

【问题讨论】:

  • Erm...有关它为什么不起作用的更多信息会有所帮助。
  • 就是这样,我想弄清楚为什么它不能与 iOS7 一起工作。你能用你的任何 UItableViewCell 类检查这个方法吗?

标签: iphone ios ipad ios6 ios7


【解决方案1】:

我在 iOS 7 下遇到了同样的问题 - 您在 -drawRect 方法中绘制的任何内容都会被单元格的子视图遮盖。相反,将新视图子类的实例作为子视图添加到您的单元格contentView 并在那里进行绘图。

thisthis。如果您不想创建自定义子类,可以改用block drawing views

【讨论】:

  • 感谢 MrMage 给我提示。
【解决方案2】:

我已通过向 contentview 添加子视图来修复它

- (id)initWithStyle:(UITableViewCellStyle)style 
                              reuseIdentifier:(NSString *)reuseIdentifier{
      if(!self)
         return self;

      self.colorView = [[UIView alloc] initWithFrame:CGRectMake(10, 5, 40, 43)];
      self.colorView.layer.borderColor = [[UIColor blackColor] CGColor];
      self.colorView.layer.borderWidth = 1.0;
      [self.contentView addSubview:self.colorView];

  }

- (void)setActivityColor:(UIColor*)color
{
    [self.colorView setBackgroundColor:color];
}

【讨论】:

    猜你喜欢
    • 2013-09-16
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多