UIView에서 특정 크기의 새 버튼을 만들려고합니다. 이런 일이 발생하면이 뷰는 tableViewCell에서 사용됩니다. iPhone UIButton setFrame이 잘못된 프레임 크기를 반환합니다.
UIImageCtrlBtnView *newView = [self initImageCtrlBtnsInViewWithHeight: 50 withWidth : 280];
[cell.contentView addSubview:newView];
나는 새로운 뷰와 방법 initImageCtrlBtnsInViewWithHeight에서 버튼의 무리를 만듭니다.
-(UIView*) initImageCtrlBtnsInViewWithHeight: (CGFloat) rowHeight withWidth: (CGFloat) rowWidth {
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rowWidth, rowHeight)];
newView.tag = kImageCtrlBtnViewTag;
newView.clipsToBounds = YES;
// finding the right size of the button by setting the button size to some fraction
// of the view size.
CGRect largeButtonFrame = CGRectMake(rowWidth*0.1+newView.frame.origin.x, rowHeight*0.2+newView.frame.origin.y, rowWidth*0.8, rowHeight*0.6);
UIButton *largeMoreButton = [UIButton buttonWithType:UIButtonTypeCustom];
largeMoreButton.tag = kLargeMoreBtnTag;
[largeMoreButton setTitle:@"Add Photo" forState:UIControlStateNormal ];
[largeMoreButton setFrame: largeButtonFrame];
// I check the size of the button frame.
DLog(@"large more btn frame: %d, %d, %d, %d", largeMoreButton.frame.origin.x, largeMoreButton.frame.origin.y, largeMoreButton.frame.size.width, largeMoreButton.frame.size.height);
etc.
문제는 setFrame 이후에 버튼을 다시 가져올 때 문제가 발생한다는 것입니다. 다음은 로그의 출력입니다. 버튼은 1076101120 고 버튼이라고 생각합니다!
large more btn frame: 0, 1077706752, 0, 1076101120
디버그 로그에서 largeButtonFrame 사각형의 값을 확인했는데 예상대로입니다. 뷰가있는 tableView에 표시됩니다 결국
(gdb) print largeButtonFrame
$1 = {
origin = {
x = 28.5,
y = 10
},
size = {
width = 228,
height = 30
}
}
은,이 오류 메시지 및 CGContext의 errrors의 무리를 얻을. 내 테이블이 표시되면
-[<CALayer: 0xff7b550> display]: Ignoring bogus layer size (320.000000, 1120403456.000000)
-[<CALayer: 0xff778a0> display]: Ignoring bogus layer size (300.000000, 1120403456.000000)
는 버튼을 적당한 크기처럼 보이지만,이 셀은 기본적으로 테이블보기에서 영원히 확장하고 난 뒤에 다른 세포의에 스크롤 할 수 없습니다.
다른 방법으로 단추 크기를 설정하려고 시도했습니다 (예 : 단추 테두리를 설정 한 다음보기 중앙에 배치하거나 UIButton buttonWithType 작성자를 사용하여 프레임 설정). 그러나이 중 아무 것도 보이지 않습니다. 차이를 만들다.
오류 메시지를 검색하면 사람들이 애니메이션 작업을 시도 할 때만이 오류 메시지가 표시됩니다. 그러나 여기 애니메이션을하려고하는 것이 아니라 단지 버튼을 설정하는 것뿐입니다.
그게 전부 였어! 내 heightForRow에 NSInteger를 반환 했으므로 프레임이 올바르게 생성 된 동안 cell.contentView는 그렇지 않습니다. – Yenyi