Nib文件中TableViewCell的视图大小



我试图获得UIImageView的宽度,这是在笔尖文件使其圆形,但我得到错误的值

下面是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
   //....
   UINib *cellNib = [UINib nibWithNibName:@"User_Row" bundle:nil];
   [_Menu_Table registerNib:cellNib forCellReuseIdentifier:@"user_row"];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    User_Row *user_row = [tableView dequeueReusableCellWithIdentifier:@"user_row"];
    if (user_row == nil){
        NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"User_Row" owner:self options:nil];
        user_row = (User_Row *)[nibs objectAtIndex:0];
    }
    [user_row.user_image layoutIfNeeded];
    user_row.user_image.layer.borderWidth = 3;
    user_row.user_image.layer.borderColor = [UIColor colorWithRed:40/255 green:62/255 blue:38/255 alpha:1].CGColor;
    CALayer *cellImageLayer = user_row.user_image.layer;
    NSLog(@"width is %f", user_row.user_image.frame.size.width);
    [cellImageLayer setCornerRadius:user_row.user_image.frame.size.width/2];
    [cellImageLayer setMasksToBounds:YES];
    return user_row;
}
int imgHeight =  imageView.layer.frame.size.height;
int imgWidth = imageView.layer.frame.size.width;
NSLog(@"height of image %i",imgHeight);
NSLog(@"widht of image %i",imgWidth);

通过替换:

[user_row.user_image layoutIfNeeded];

user_row.frame = CGRectMake(0, 0, self.view.frame.size.width, row_height);
[user_row layoutIfNeeded];

但是我想要一个解释

相关内容

  • 没有找到相关文章

最新更新