我在情节提要UIView
的自定义单元格中添加了一个,UITableView
然后像这样访问它:
UIView *customView = (UIView *)[cell viewWithTag:CELL_CUSTOM_VIEW_TAG];
NSLog(@"%f", customView.frame.size.width);
但我知道它的宽度0.0000
。我是否以错误的方式访问它?
编辑:这是我的完整 cellForRow 方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIImageView *customImageView = (UIImageView *)[cell viewWithTag:CELL_IMAGE_VIEW_TAG];
customImageView.image = [UIImage imageNamed:@"foo.jpg"];
//down is the code why I need the frame of it
//I'm trying to make a right border to this UIImageView:
CGRect imageViewFrame = customImageView.frame;
CALayer *imageViewRightBorder = [self rightBorderWithColour:[UIColor blackColor] forView:imageViewFrame];
[customImageView.layer addSublayer:imageViewRightBorder];
return cell;
}
这是我为 imageView 设置右边框的方法:
- (CALayer *)rightBorderWithColour:(UIColor *)color forView:(CGRect)viewFrame {
CALayer *rightBorder = [CALayer layer];
rightBorder.frame = CGRectMake(viewFrame.size.width, 0.0f, 1.0f, viewFrame.size.height);
rightBorder.backgroundColor = [color colorWithAlphaComponent:1.0f].CGColor;
return rightBorder;
}