2012-09-21 8 views
2

imageview의 왼쪽 위 모서리와 오른쪽 하단 모서리에 삭제 버튼을 만들려고합니다. 그러나 그것은 내가 필요로했던 것처럼 보이지 않는다.UIImageView의 왼쪽 위 모서리와 오른쪽 아래 모서리에서 UIButton을 만드는 방법

enter image description here

나는 두 버튼 내가

UIImageView * tappedView = (UIImageView *)[recognizer view]; 

[tappedView.layer setBorderColor: [[UIColor redColor] CGColor]]; 
[tappedView.layer setBorderWidth: 2.0]; 
tappedView.layer.cornerRadius = 10; 
tappedView.layer.masksToBounds = NO; 


UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 
deleteBtn.frame = CGRectMake(0, 0, 20, 20); 

[deleteBtn setImage:[UIImage imageNamed:@"close.png"]forState:UIControlStateNormal]; 

deleteBtn.layer.shadowColor = [[UIColor blackColor] CGColor]; 
deleteBtn.layer.shadowOffset = CGSizeMake(0,4); 
deleteBtn.layer.shadowOpacity = 0.3; 
[tappedView addSubview:deleteBtn]; 
[deleteBtn addTarget:self action:@selector(deleteProperties:) forControlEvents:UIControlEventTouchUpInside]; 



UIButton *zoomBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 
zoomBtn.frame = CGRectMake(tappedView.frame.size.width, tappedView.frame.size.height, 20, 20); 

[zoomBtn setImage:[UIImage imageNamed:@"close.png"]forState:UIControlStateNormal]; 

zoomBtn.layer.shadowColor = [[UIColor blackColor] CGColor]; 
zoomBtn.layer.shadowOffset = CGSizeMake(0,4); 
zoomBtn.layer.shadowOpacity = 0.3; 
[tappedView addSubview:zoomBtn]; 
[zoomBtn addTarget:self action:@selector(ZoomIn:) forControlEvents:UIControlEventTouchUpInside]; 

아래의 코드를 사용하는 버튼을 만들려면 나를 인도 해주십시오 빨간색 테두리

의 코너에 배치해야 바랍니다.

나는 그냥 버튼의 프레임 함께 놀러이 enter image description here

답변

1

같이합니다 : 예를 들어,

deleteBtn.frame = CGRectMake(-5, -5, 20, 20); 

상기 제 2 개 번호와 같은

zoomBtn.frame = CGRectMake(tappedView.frame.size.width - 20, tappedView.frame.size.height - 20, 20, 20); 

는 좌표 X 및 Y이며, 프레임을 포함하는 뷰 프레임에 상대적이다.

+0

예. 나는 (-5, -5,20,20) 정확한 위치에 배치하지만 빨간색 테두리는 버튼에 나타나는 경우 이미 그 중 하나를 시도했다. – thavasidurai

+0

@ 브렌드는 내 게시물을 삭제해야합니까? 모두 같은 소리 .... – Spynet

+0

@ 브렌드 내가 내 질문 pls 그것을 편집했습니다. – thavasidurai

0

zoomBtn.frame 대신 zoomBtn.center를 사용하면 버튼의 크기를 고려하지 않아도됩니다. 모든 크기 버튼에서 작동합니다.

// Create the button's frame - doesn't matter the x & y 
CGRect btnFrame = CGRectMake(0.0f, 0.0f, 20.0f, 20.0f); 

zoomBtn.frame = btnFrame; 

// Set the zoomBtn center to the bottom right corner 
zoomBtn.center = CGPointMake(tappedView.frame.size.width, tappedView.frame.size.height); 

deleteBtn.frame = btnFrame; 

// Set the deleteBtn center to the top left corner 
deleteBtn.center = CGPointMake(0.0f, 0.0f);