How to use UIBezier Path For Making UIButton [closed] - ios

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have to make UIButton in Specify Shape.That Shape have to convert in UIButton How Can i do..plz Help..!!

One suggestion would be to create the shape you want using a CAShapeLayer and add a touch detector to it that triggers an action.
If you're unfamiliar with CALayer and its many applications Ray Wenderlich has an excellent overview here.

First of all UIBezier Path is not For Making UIButton it is for giving a shape for UIButton.
Second, if you want to give shape to your UIButton then Apple provided all detail regarding BezierPaths in their document.
As ican understand you need to shape button like Curve shape then on Apples document provided method here .
#define DEGREES_TO_RADIANS(degrees) ((pi * degrees)/ 180)
- (UIBezierPath *)createArcPath
{
UIBezierPath *aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150)
radius:75
startAngle:0
endAngle:DEGREES_TO_RADIANS(135)
clockwise:YES];
return aPath;
}
There are two mainly curve provided by apple and inbuilt method in beizear path.
You need to use Quadratic curve to shape your UIButton.
Please check this link.
addQuadCurveToPoint:controlPoint
and Use inbuilt method and change endpoint and controlpoint According to your shape.
Note:- You need to change the point according to your Requirement.

Related

iOS development: interactive graph [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Please take a look at the image above. The red circles represent user's touching motion. So if the user touched where the first circle is (to the left), then there should be a graph that's skewed to the left. If user touched in the middle, a normally distributed graph. If the user touches the right part, the graph should be skewed right.
I am new to iOS development and I am wondering how I can achieve such feature. Any recommendation to suitable libraries, frameworks, documents will be greatly appreciated.
OK, let's go through the components of that one at a time.
To know where the user touches, you could use something like a UIPanGestureRecognizer or UITapGestureRecognizer.
To draw a curve, a common technique is to add a CAShapeLayer:
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.strokeColor = [UIColor blueColor].CGColor;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.lineWidth = 4.0;
[self.view.layer addSublayer:shapeLayer];
You can then set the path for that CAShapeLayer, and every time you change the path, the curve on the view will change. If you change that path frequently (e.g. you use a UIPanGestureRecognizer that is called every time the user's finger moves), you are effectively animating the change of the curve.
So, how do you create the path? Well, you just create a UIBezierPath
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:...];
// build the path as a series of curves
//
// [path addCurveToPoint:...
// controlPoint1:...
// controlPoint2:...];
// or a series of lines that are so numerous that it looks like a nice curve
//
// for (NSInteger x = 0; x <= view.bounds.size.width; x++) {
// [path addLineToPoint:...];
// }
shapeLayer.path = path.CGPath;
So, the only question is whether the curve needs to be a normal distribution, or whether you just want something that draws a smooth curve with a local maximum where the user touched.
If you want something that exactly and mathematically represents some particular curve (e.g. if in the center, it's a true normal distribution), then you need to come up with the equation to represent your curve (as a function of where the user tapped). Then you draw your curve by plotting a whole bunch of points using addLineToPoint with a UIBezierPath.
If you only need something that looks close, then you can approximate it with two bezier paths (created with addCurveToPoint:controlPoint1:controlPoint2:).
We're not going to write this for you, but these are the basic building blocks of the solution. I'd suggest you take these one at a time, do a little research on each, try it out, and then refine. Start small and build from there.

What is the difference between CGPath and UIBezierPath()? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
At the moment, I'm trying to work out how to animate a custom button which I have an image of and have the coordinates of but I've found that you can create a button/object both by using the CGPath class or the UIBezierPath class. Can somebody please tell me what the difference between the two are?
CGPath is an opaque type from the CoreGraphics library, while UIBezierPath is an Obj-C class in UIKit. UIBezierPath is a wrapper around CGPath (you can convert between them easily), with a more object-oriented interface and a few convenience methods. Using CGPath may be marginally faster as it doesn't have to go through Obj-C (although who knows how it works with Swift) and it has more advanced functions like CGPathApply. Importantly, UIBezierPath conforms to NSCoding, meaning you get serialization/deserialization for free.
tl;dr: use UIBezierPath unless you have some reason not to.
To expand a bit on what jtbandes wrote, there's another distinction: CGPath is just a mathematical description of a shape. It has no drawing-specific properties or capabilities. Instead, drawing properties are part of the CGContext as is the actual drawing operation. You set things like color, line width, etc. on the context before the drawing operation, but those are not part of the path itself.
By contrast, UIBezierPath has drawing properties and drawing operations.

Motion paths drawn by finger [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am interested in making path with finger (like connecting objects) between two elements. I am not sure how would I start on this.
I know that I could use Bezier path to create lines, but I am not sure how to create that line with finger. Does anyone have some good example?
I tried to google it, but I can't find anything like that made.
Thanks
I answered a question recently about slow/laggy performance on a similar setup. I.E. Drawing UIBezierPaths in CALayer. The answer contains a subclass of UIView which you can drop into a storyboard and will pretty much get you started. The header file is not shown in the answer, but it is literally a subclass of UIView (just add a UIView Subclass to your project). You should be able to copy the rest into your implementation file. Obviously you'll want to take out the performance testing code.
touchesMoved drawing in CAShapeLayer slow/laggy
If you simply want to Add a single line, you just need to get the starting point in touchesBegan, and build the path in touchesMoved. The commitCurrentRendering simply renders the touch points accumulated, then clears the UIBezierPath. This improves the performance as there wass a notable slowdown when UIBezierPath reached around 2000 points (touchesMoved will feed you a succession of points as your finger moves).

Is it possible to assign color to targeted coordinates x to y without having to upload a UIimage [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to know whether it is possible to assign colors to different coordinates in the IOS and how it can be accomplished. In other words for example making a black square by assigning colors to x,y coordinates.
As per you question, I have understood that you are looking for API to fill a pixel with a color based on the coordinates. To achieve this you can use UIBezierPath class. I wrote a sample example to achieve this.
I have created a subclass of UIView called CustomView and overriden drawRect method like below :
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 100, 100)];
[[UIColor blackColor] set];
[path fill];
}
UIBezierPath class can be used to lay your custom drawing on your view. A path basically represents an area where you can fill different colors in it. The above example will draw a rectangle at x = 50 y = 50 coordinates with width and height of 100 each.
If you want to just fill color to a point, then create bezier path instance like below :
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 1, 1)];
Replace your's View Controller's class name from UIView to CustomView. When you run your app you should see following output :
Your question is too vague and doesn't really make sense. Yes, you could develop an app that stored a grid of pixel colors and then drew them to the screen. However a UIImage or a CGImage (the underlying data structure behind a UIImage) is a good native way to represent pixel data on iOS.
What you typically do is create an off-screen graphics context and draw into that context, then extract an image from the context.

is it possible to make custom shaped buttons in iOS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Or some kind of UI objects that can
interact with users
be drawn into any shape, for example, oval.
yes. It is pretty simple.
UIImage *buttonImage = [UIImage imageNamed:#"greenButton.png"];
UIImage *buttonImageHighlight = [UIImage imageNamed:#"greenButtonHighlight.png"];
[myCustomButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[myCustomButton setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted];
It is possible to do it in a variety of ways. Rydgaze gave you the option for using a UIImage as your custom button. If you are looking for a code only way then I would suggest UIBezierPath. UIBezierPath allow's you to draw any shape that you want as well as customize the look. With UIBezierPath I could draw a star and fill it with anything that I would like.
Here is the link to the Reference: https://developer.apple.com/library/ios/documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html
The idea is that you create a view class. In that view's drawRect method you will design whatever shape you are looking to create and customize it to what you see fit. For you button you would set its self.view to be the view that of your custom UIBezierPath class. That will just draw your custom shape as the button.
The advantage's to writing your button's in code are that it will for one be faster. It also takes up significantly less size because it isn't storing an image file. Also you are able to continue the customization of your shape. That mean's you could change the color, dimensions, etc. very easily.

Resources