is it possible to make custom shaped buttons in iOS [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 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.

Related

iOS: How to partially change the color of text [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 6 years ago.
Improve this question
I was playing with iOS built-in Compass app and the UI do make me curious.
Here is the interesting part:
The color of text (even the circle) can be partially and dynamically changed.
I have made a lot of search, but the results are all about attributed string. How to implement the effect like this?
Edited:
I have tried to add two UILabels (whiteLabel and blackLabel) as whitelabel at the bottom and blackLabel at the top with the same frame. Then I set the circle as the mask of blackLabel.
The problem is 'whiteLabel' is totally covered by blackLabel, and if the circle do not intersect with 'blackLabel', both labels are not visible.
I imagine that there are two "14" labels in the same place. The bottom one is white and unmasked, and the top one is black and has a layer mask that contains two circles, so it's only visible where the circles are.
Achieving this has most probably nothing to do with NSAttributedStrings, like Woodstock said.
I'd say it's the UILabel's layer that is recolored live, depending on what other layer it intersects with, and the overlaying area of said intersection.
Once you figure those common points, you just apply a mask that inverts colors from there.
Now it's a little bit more complicated than that since there appears to be two circles (hence two layers to find intersections with), but in the end, it's "just a list of coordinates" that the label's coordinates intersects or not.
That could be an interesting exercise ; it would probably take me a decent amount of tries to mimic that behaviour, but I'm pretty confident my reasoning is on point. (get it? :o)

How to use UIBezier Path For Making UIButton [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 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.

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.

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.

Custom Marker icon Google Maps iOS with image in image? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I try to create many markers in map with icon is a png image like placeholder.
After that i want to set an other image inside of each placeholder.
It looks like this.
My problem is how to set image inside image of marker.
How to do that?
You would need to write code which takes the background image (eg the frame) and adds on the sub-image (eg the food picture), to create a combined UIImage. Then you could use the combined UIImage as the marker's icon.
Check out these questions for some examples of how to draw 2 UIImage objects into a single UIImage:
Draw another image on a UIImage
Attempting to draw image on top of another image using a touch event

Resources