0

I wanna draw a UIButton filled with a red tint color or some color else presented by rgb and only the upper edges are rounded.
some people answer me to get an image to do that but every time i want to change it i have to bring new image and replace it, I wanna ask can i do it from code without get an image.

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
Omar Freewan
  • 2,678
  • 4
  • 25
  • 49
  • Possible duplicates : http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview and http://stackoverflow.com/questions/4845211/just-two-rounded-corners – rdurand Oct 11 '12 at 07:36
  • thank you @rdurand this was helpful next to ACB answer – Omar Freewan Oct 11 '12 at 08:20

2 Answers2

0

There is no direct way. Only way to achieve this to create a segment control and keep only a single segment in that.

See this post for detailed implementation,

Update:

If you want to round only two corners check Round two corners in UIView or Just two rounded corners? as mentioned in rdurand's comment. Since segment control is a subview of UIView, this should work.

Community
  • 1
  • 1
iDev
  • 23,310
  • 7
  • 60
  • 85
  • All corners are already rounded right? Check the image in http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem. If you want to round only the two corners check the comment by rdurand on question. – iDev Oct 11 '12 at 08:10
  • Updated my answer with those links. – iDev Oct 11 '12 at 08:25
0

You can draw the rounded corners using NSBezierPath s bezierPathWithRoundedRect:xRadius:yRadius: method. And then draw over it with another bezier path. Or you could just define a custom bezier path using moveToPoint: lineToPoint: and curveToPoint:controlPoint1:controlPoint2:

Take a look at this: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html

IluTov
  • 6,807
  • 6
  • 41
  • 103