Draw a Rounded Rectangle programmatically [duplicate] - iphone

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to draw a rounded rectangle in Core Graphics / Quartz 2D?
I want to draw a rounded rectangle programmatically for my overlaying UIView,
how would I approach this?

NSBezierPath has a special +bezierPathWithRoundedRect:xRadius:yRadius:, check the documentation.
NSBezierPath *path =
[NSBezierPath bezierPathWithRoundedRect:NSMakeRect(...)
xRadius:3.0f
yRadius:3.0f];
[path fill];

Related

Gradient on a UILabel? [duplicate]

This question already has answers here:
How to Apply Gradient to background view of iOS Swift App
(30 answers)
Closed 4 years ago.
I am trying to create a UILabel that will have a gradient background color. I am wondering if there is a way to do this through the interface builder. If not, is there a way to accomplish this programmatically using the Swift programming language?
Any input or suggestions are greatly appreciated.
Thanks in advance.
You actually can't put directly a gradient layer in a UILabel, since the text will dissapear. See Adding a CGGradient as sublayer to UILabel hides the text of label
You can use an UIView, put your UILabel inside it, and then add the gradient layer to the UIView like this.
How to Apply Gradient to background view of iOS Swift App
While not the same question, it seems the answer to this may help:
How to Apply Gradient to background view of iOS Swift App
You have to create a gradient layer and insert it as a sublayer programmatically.

UIViews-masked-off-area-still-touchable [duplicate]

This question already has an answer here:
Mask UIView Touch Detect [closed]
(1 answer)
Closed 9 years ago.
I have Masked UIView . View with blue dots. Green circle Area is masked off.I dont want to get touches on that area.i just want to get touches on visible layer of the View.
Please select touch view in your touch method in place of self.view
May be it helps
Try creating a CGPath of the masked area & then check if the touch falls in ur masked area or not like this :
UIBezierPath *p = [UIBezierPath bezierPathWithCGPath:myCGPath];
BOOL isInPath = [p containsPoint:myCGPoint];
Hope this Helps !!!

Create Circular Button in iPhone SDK [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 4 years ago.
Improve this question
Can any one tell me how to create the rounded button (Circular Button) in iPhone by using interface builder?
If you want a circular button than create an image with a circular shape filled with whatever you want to be displayed in the circle. Make sure your image has an alpha channel and delete all the area around your circle so the background of your image is transparent (alpha =0). (gimp is free and easy to use application for such images)
In IB create a round rect button with type custom button. Select your image as the background of your button and there you have it.
Hope this will help
#import <QuartzCore/QuartzCore.h>
CALayer * l = [control layer];
[l setMasksToBounds:YES];
[l setCornerRadius:5.0];
[l setBorderWidth:2.0];
Adjust cornerRadius according to your need..

How can I round just the bottom corners of a UIView? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
UIView with rounded corners
Round two corners in UIView
I'm aware of means for rounding all four corners of a UIView, but how could I round only the bottom corners of a view?
To achieve this, you need to use CALayer masking. This question Just two rounded corners? and the accepted answer should get you started. If you run in to trouble, then you should take a look at this follow-up post: Round two corners in UIView
You can draw in one CALayer filled rectangle with bottom rounded corners and than set it as mask to your:
[[view layer] setMask:calayerWithDrawedMaskingRect];

Want to make a text editor.. how to apply background image to TextView? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
UITextView background image
I want to add a background image to a textview. Can it be done through the interface editor?
If not, what will be the code required to do so?
I want the text to scroll with the background image as the number of lines with text increase.
Well I found the following way, using patternImage. Multiple lines can be made, pattern will contain a single line :)
textView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: #"line.png"]];
Just put UIImageView with your desired image, and, above that, use textview with ClearColor Background.