2011-05-31 26 views
8

UIBackBarButtonItem'e benzeyen bir UIButton yapmak istiyorum (gezinme yığını için solu gösteren bir ok ile. Mümkünse bir görüntü kullanmak zorunda kalmadan bunu yapmayı tercih ederim. düğme telefonun yönüne bağlı olarak farklı bir boyuta sahip olacaktır. Özel UIButton Şekil kullanmadan şekil

bu kodda etkileyen aktif bir yolu var mı? Benim fikrim her nasılsa düğmeye CALayer kullanıyordu.

teşekkürler!

DÜZENLEME

@ Deepak'in tavsiyesini kullanmaya çalışıyorum, ama bir sorunla karşılaşıyorum. Düğmenin sağ tarafını, sol taraftaki ok gibi görünen [UIBezierPath bezierPathWithRoundedRect: rect cornerRadius: 4] gibi görünmesini istiyorum. Bunu addQuadCurveToPoint: controlPoint yöntemini kullanarak yapmaya çalıştım.

Denetim noktası olarak rect köşesini kullanıyorum, ancak yol beklediğim gibi eğri vermiyor. Ben sadece addLineToPoint: yöntemini kullanmışım gibi hala köşeli. Kodum aşağıda.

float radius = 4.0; 
UIBezierPath *path = [UIBezierPath bezierPath]; 

CGPoint startPoint = CGPointMake(rect.size.width/5.0, 0); 
CGPoint pointBeforeTopCurve = CGPointMake(rect.size.width - radius, 0); 
CGPoint topRightCorner = CGPointMake(rect.size.width, 0); 
CGPoint pointAfterTopCurve = CGPointMake(rect.size.width, 0.0-radius); 

CGPoint pointBeforeBottomCurve = CGPointMake(rect.size.width, rect.size.height-radius); 
CGPoint bottomRightCorner = CGPointMake(rect.size.width, rect.size.height); 
CGPoint pointAfterBottomCurve = CGPointMake(rect.size.width - radius, rect.size.height); 

CGPoint pointBeforeArrow = CGPointMake(rect.size.width/5.0, rect.size.height); 
CGPoint arrowPoint = CGPointMake(0, rect.size.height/2.0); 


[path moveToPoint:pointBeforeTopCurve]; 
[path addQuadCurveToPoint:pointAfterTopCurve controlPoint:topRightCorner]; 

[path addLineToPoint:pointBeforeBottomCurve]; 
[path addQuadCurveToPoint:pointAfterBottomCurve controlPoint:bottomRightCorner]; 


[path addLineToPoint:pointBeforeArrow]; 
[path addLineToPoint:arrowPoint]; 
[path addLineToPoint:startPoint]; 
+0

Kontrolü için çizim zorluklar çözmüş bu http://stackoverflow.com/questions/6184321/where-can-i-find-some-beautiful-iphone-buttons/6184393#6184393 – Jhaliya

+0

Ne çözdü? –

+0

Ne demek istiyorsun? –

cevap

7

Bunu Quartz ile yapabilirsiniz. UIButton alt sınıfına ihtiyacınız olacak ve drawRect: yöntemini uygulayacaksınız. Bir yolu tanımlamanız ve bir degrade ile doldurmanız gerekir. Dikdörtgen olmayan bir şekil içerdiğinden, 'u da uygulamanız gerekecektir.

0

Bu beni

float radius = 10.0; 
UIBezierPath *path = [UIBezierPath bezierPath]; 

CGPoint startPoint = CGPointMake(rect.size.width/5.0, 0); 
CGPoint pointBeforeTopCurve = CGPointMake(rect.size.width - radius, 0); 
CGPoint topRightCorner = CGPointMake(rect.size.width, 0.0); 
CGPoint pointAfterTopCurve = CGPointMake(rect.size.width, radius); 

CGPoint pointBeforeBottomCurve = CGPointMake(rect.size.width, rect.size.height-radius); 
CGPoint bottomRightCorner = CGPointMake(rect.size.width, rect.size.height); 
CGPoint pointAfterBottomCurve = CGPointMake(rect.size.width - radius, rect.size.height); 

CGPoint pointBeforeArrow = CGPointMake(rect.size.width/5.0, rect.size.height); 
CGPoint arrowPoint = CGPointMake(0.0, rect.size.height/2.0); 


[path moveToPoint:pointBeforeTopCurve]; 
[path addQuadCurveToPoint:pointAfterTopCurve controlPoint:topRightCorner]; 

[path addLineToPoint:pointBeforeBottomCurve]; 
[path addQuadCurveToPoint:pointAfterBottomCurve controlPoint:bottomRightCorner]; 


[path addLineToPoint:pointBeforeArrow]; 
[path addLineToPoint:arrowPoint]; 
[path addLineToPoint:startPoint]; 


[path fill];