How can I add a picture frame to an UIImage? - iphone

I am working on an iphone application where I want to add a different frame(e.g. black grit, oldtime, etc) to an image and save that image with that frame.
Is it possible in iphone application. Please give me suggestion.Thanks.

Check this question.
You need to implement following code:
#import <QuartzCore/QuartzCore.h>
[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];

Related

set bordercolor for image which is in array

I have images in an array, and when I display those images on view, it should appear with the border. How do I set the border color?
for(UIImage *img in imagesArray)
{
//for bordercolor
}
First Add QuartzCore.framework framework in your project from Build Phases => Link Binary with Libraries => Add button(+) and after import its file in your class like bellow...
#import <QuartzCore/QuartzCore.h>
and use bellow code for set color..
yourImageView.layer.borderWidth = 2.0;
yourImageView.layer.borderColor= [UIColor redColor].CGColor;
UPDATE:
-(IBAction)lockword:(id)sender {
for (UIImage *img3 in imagesArray) {
UIImageView *imgview1=[[UIImageView alloc]initWithImage:img3];
imgview1.layer.borderWidth = 2.0;
imgview1.layer.borderColor = [UIColor redColor].CGColor;
[imgview1 release];
// your other code write here
// Add this UIImageView as a subview of your view with its frame...
}
}
#import <QuartzCore/QuartzCore.h>
[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
To allow editing the border color property of your imageview, you need to add Quartzcore framework
Add it from : Link Binary with Libraries option and then write the following code where you want to change the border color :
[imageview.layer setBorderWidth:2.0]; // set the border width to any value you want so that your bordercolor would appear accordingly
[imageview.layer setBorderColor:[[UIColor blueColor].CGColor]; // set the color to whatever background color you want to set to your image

How can i change the fill color of a CALayer in Core Graphics?

I have a shape, a CALayer, which I want to add core graphics effects to. Right now, I want to keep it simple and change the fill colour of it. How can I do this?
If you just want to change the color of the whole layer you can use:
layer.backgroundColor = [[UIColor greenColor] CGColor];
if you have a more complex shape like a path to fill, you need to overwrite the layer's drawInContext: with sth like this:
- (void)drawInContext:(CGContextRef)context
{
//...
CGContextSetFillColorWithColor(context, [[UIColor greenColor] CGColor]);
CGContextFillPath(context);
//...
}
See Quartz 2D Programming Guide for more info.
shape.fillColor = [UIColor blackColor].CGColor;
[[UIColor redColor] setFill] is what you're looking for, I believe.
I don't have Xcode open atm, but that should be the right method if you're trying to fill a path.

Gradient Stroke on UIButton

I've found the GradientButton class for gradients on a UIButton - however I can't figure out how to get a matching stroke around the button. How do you create a gradient stroke on the button?
You need to use CALayer for this:
[[button layer] setCornerRadius:8.0f];
[[button layer] setMasksToBounds:YES];
[[button layer] setBorderWidth:1.0f];
And dont forget to import:
#import <QuartzCore/QuartzCore.h>
Here is a good tutorial of making tutorial with Core Animation by Matt Long
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/

Rounded Rectangle Issue

I have seen many Q's on this subject but none are exactly what I am trying to do. I have a view inside of a view and it's frame is a CGRectangle. I would like said rectangle to have rounded edges to look like a rounded rectangle button. If I could have some code examples on how to implement that it would be nice. Thank you in advance.
You first need to import QuartzCore framework into your project. I hope you know how to do that. Than you can use the following code:
CALayer *l = [yourView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];
// You can even add a border
[l setBorderWidth:1.0];
[l setBorderColor:[[UIColor blackColor] CGColor]];
Hope it helps! ;)
You need to make sure you import <QuartzCore/QuartzCore.h> and add QuartzCore to the Existing Frameworks in order to gain access to the cornerRadius: method.
Then to set the corner radius you would use something like the following depending upon your implementation of the view
UIView *theView = [[UIView alloc] initWithFrame:CGRectMake(10,10,100,200)];
CALayer *theViewLayer = [theView layer];
[theViewLayer setCorderRadius:5.0];
//Other Methods you can use
[theViewLayer setBorderColor:[[UIColor colorWithWhite:1.0 alpha:0.3] CGColor]];
[theViewLayer setBorderWidth:2.0];
[theViewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];

border in UIImageView

I am trying to have an UIImageView bordered like the following:
I have tried using:
[imageView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
but then you can't see that gray border on the outside. It has that gray shadow effect on the outside.
How do I do this?
Take a look at the shadow properties of CALayer.
[imageView.layer setShadowOffset:CGSizeMake(-1.0, -1.0)];
[imageView.layer setShadowOpacity:0.5];
This question about adding shadows to UIImageView might help
imageView.layer.shadowOpacity=0.6;
imageView.layer.shadowRadius = 0.0;
imageView.layer.shadowColor = [UIColor grayColor].CGColor;
imageView.layer.shadowOffset = CGSizeMake(-2.0, 1.0);