2017-04-21 1 views
0

여기에 문제가 있습니다. 버튼이 배경 이미지의 크기에 완벽하게 맞기를 바랍니다. 예를 들어배경 이미지에 맞게 버튼 크기 조절

:

Image Example

당신이 볼 수 있듯이, "요청 계획"다이아몬드 주위에 상자가 겹치거나 "보기 계획"다이아몬드를 통해 가고, 실행 시간에 I가 클릭 할 때 "View Plan"다이아몬드는 실제로 "Request Plan"다이아몬드를 클릭하기 때문에 중복됩니다. 이 문제를 해결할 수있는 방법이 있습니까?

+0

하여 확인할 수 있습니다. 이 경우 배경 이미지가 "rotate"되어야합니다. – jokeman

+0

@jokeman 회전 옵션을 찾지 못했습니다. 어떻게해야합니까? – user3694341

+1

'self.myButton.transform = self.myButton.transform.rotated (CGFloat (M_PI_4))'당신의 버튼을 초기화 할 때 – jokeman

답변

0

당신은있는 UIButton 다음 pointInside

override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool { 
    *we need check at this point inside or outside* 
    return self.alphaAtPoint(point) >= 127 
} 

오버라이드 (override) 확장 CustomButton 클래스를 만들 수 있습니다 우리는 당신이 다음 회전 정상적인 버튼을 만들 수 있습니다 체크 alpha

func alphaAtPoint(point: CGPoint) -> CGFloat { 
    var pixel: [UInt8] = [0, 0, 0, 0] 
    let colorSpace = CGColorSpaceCreateDeviceRGB(); 
    let alphaInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue) 
    let context = CGBitmapContextCreate(&pixel, 1, 1, 8, 4, colorSpace, alphaInfo) 

    CGContextTranslateCTM(context, -point.x, -point.y); 

    self.layer.renderInContext(context) 

    return CGFloat(pixel[3]) 
} 
0

스토리 보드에서 무엇이든 똑같이 길게하려면 다른 오브젝트로 드래그하고 "같음 너비"및 "같음 길이"를 선택하십시오. 중첩과 관련하여 버튼 또는보기의 순서를 변경하거나 다시 만들 수 있습니다.

관련 문제