약간의 수정 작업을 수행하기 위해 자동으로 생성 된 tableView에서 imageView의 너비와 높이를 읽으려고합니다.IOS/Objective-C : 프로그래밍 방식으로 만든 tableview의 imageView 크기 결정
그러나 일반적으로 imageView가 명시 적으로 정의되지 않았기 때문에 제가 일반적으로 사용하는 방법은 너비가 0을 반환하는 것입니다. 누구든지이 일을 할 수있는 방법을 알고 있습니까?
float imageWidth =cell.imageView.frame.size.width;
참고 :
-(void) makeTableView {
//origin,origin,width,height
_myTableView = [[UITableView alloc] initWithFrame:
CGRectMake(160, 114, 140, 100) style:UITableViewStylePlain];
_myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_myTableView.delegate = self;
_myTableView.dataSource = self;
_myTableView.scrollEnabled = YES;
_myTableView.layer.cornerRadius = 5;
_myTableView.hidden = YES;
_myTableView.backgroundColor = [UIColor grayColor];
_myTableView.rowHeight=24;
_myTableView.layer.borderColor=[UIColor grayColor].CGColor;
_myTableView.layer.borderWidth=1;
[self.view addSubview:_myTableView];
}
가 아마 여기에 이미지 크기를 설정하는 방법이 있지만, 나는 그것이 어떻게 될지 모르는이 내가있는 tableview를 만드는 오전 방법이다.
또는이 값을 here으로 설정할 수는 있지만 tableviewcell을 서브 클래 싱하거나 비용이 많이 드는 컨텍스트를 수정하여 이미지가 반올림되는 것을 방지 할 수 있습니다.
편집 : 내 현재 cellforRowAtIndexPath
나는 코드 아래 사용하여 이미지 뷰의 크기를 설정할 수 있습니다 보인다. 그러나 일반적으로 아래 코드는 입력 사진의 크기에 관계없이 멋진 원형 이미지를 만듭니다. 모든 사각형이 정사각형이 아닙니다. 대신 일부 이미지는 둥글게 나오지만 다른 이미지는 타원형으로 나옵니다. 그래서 뭔가 프레임 크기를 설정 한 후 ... 여기
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
if (tableView == myTableView) {
static NSString *myRowIdentifier = @"myRowIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:myRowIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myRowIdentifier] ;
}
Items* item = [_items objectAtIndex:indexPath.row];
cell.textLabel.text = item.name;
NSString*pic = item.pic;
if (pic.length >=3) {
cell.imageView.image = [self loadImageNamed:pic];
}
else {
cell.imageView.image = [UIImage imageNamed:@"placeholder.png"];
}
//Because there is no custom cell, set size of imageview with following code
cell.imageView.frame = CGRectMake(0,
0,
24,
24);
cell.imageView.layer.cornerRadius = cell.imageView.frame.size.width/2;
cell.imageView.clipsToBounds = YES;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
}
당신이 당신의'cellForRowAtIndexPath' 코드를 표시 할 수 있습니다 사용 기억? –