Is it possible to add a UIImage to CPTGraph? - ios

I'm trying to add an image to a graph using Core-Plot and I want the image to move along with the graph when it being dragged or pinched. I've tried the code below but it didn't work. Can anyone tell me how to do so?
CALayer *subLayer = [CALayer layer];
subLayer.contents = [UIImage imageNamed:#"image.png"];
subLayer.position = CGPointMake(100, 120);
[_graph addSublayer:subLayer];

Use a plot space annotation:
CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] initWithFrame:imageFrame];
imageLayer.fill = [CPTFill fillWithImage:[CPTImage imageNamed:#"image.png"]];
NSArray *plotPoint = #[xCoordinate, yCoordinate];
CPTPlotSpaceAnnotation *imageAnnotation = [[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:plotSpace
anchorPlotPoint:plotPoint];
imageAnnotation.contentLayer = imageLayer;

Related

How to Apply CornerRadius and Shadow Offset for UIImageView

I am developing an E-Commerce application. I need to show product list image in rounded corner with shadowOffset. Both are not working together & i have tried with lot of solution but no one is solved my problem. Any help will be appreciate one.
Updated Code :
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20,260,45,45)];
imageView.backgroundColor = [UIColor grayColor];
UIImage *image = [UIImage imageNamed:#"sample.png"];
imageView.image = image;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:CGSizeMake(22.5, 22.5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = imageView.bounds;
maskLayer.path = maskPath.CGPath;
[imageView.layer setMask:maskLayer];
[imageView.layer setShadowOffset:CGSizeMake(0, 3)];
[imageView.layer setShadowOpacity:0.4];
[imageView.layer setShadowRadius:3.0f];
[imageView.layer setCornerRadius:22.0f];
imageView.layer.shadowColor=[UIColor redColor].CGColor;
imageView.layer.borderColor=[UIColor blackColor].CGColor;
imageView.layer.borderWidth=1.0;
[self.view addSubview:imageView];
Thanks & Regards
Sam.P

Core plot Image not scaling in ios7

UIImage *image = [UIImage imageNamed:#"tick_16.png"];
CPTImage *background = [CPTImage imageWithCGImage:image.CGImage scale:image.scale];
CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] initWithFrame:CGRectMake(0, 0, 16, 16)];
imageLayer.fill = [CPTFill fillWithImage:background];
CPTAxisLabel *iconLabel = [[CPTAxisLabel alloc] initWithContentLayer:imageLayer];
iconLabel.offset = 8;
iconLabel.tickLocation = CPTDecimalFromCGFloat(location+0.5);
Image not scaling in ios7.Please give me solution. Thanks in advance

iOS SDK - drop shadow on masked image

How to drop a shadow on UIImageView which has a masked image?
I don't mean a rectangular shadow - I'd like to apply the same mask effect to shadow too.
To give the Shadow Effect to UIImageView Try below code..
1) #import <QuartzCore/QuartzCore.h> in .h file
2) To give a shadow effect to Cell's UIImageView
mediaImage.layer.shadowColor = [UIColor blackColor].CGColor;
mediaImage.layer.shadowRadius = 10.f;
mediaImage.layer.shadowOffset = CGSizeMake(0.f, 5.f);
mediaImage.layer.shadowOpacity = 1.f;
mediaImage.clipsToBounds = NO;
Well! You can try this one.
// Use a White background to make the shadow prominent.
self.view.backgroundColor = [UIColor whiteColor];
// The image we're going to mask and shadow
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"yourImage.jpeg"]];
image.center = self.view.center;
// Make new layer to contain shadow and masked image
CALayer *containerLayer = [CALayer layer];
containerLayer.shadowColor = [UIColor blackColor].CGColor;
containerLayer.shadowRadius = 10.f;
containerLayer.shadowOffset = CGSizeMake(0.f, 5.f);
containerLayer.shadowOpacity = 1.f;
// Use the image's layer to mask the image into a circle
image.layer.cornerRadius = roundf(image.frame.size.width/2.0);
image.layer.masksToBounds = YES;
// Add masked image layer into container layer so that it's shadowed
[containerLayer addSublayer:image.layer];
// Add container including masked image and shadow into view
[self.view.layer addSublayer:containerLayer];
You can custom a subclass called NEWImageVIew inherit UIImageView.In NEWImageVIew you can make a property called realImageContainer,which you can set image to this property.
#interface NEWImageView : UIImageView
#property (nonatomic,strong) UIImageView *realImageContainer;
#end
#implementation NEWImageView
- (UIImageView *)realImageContainer {
if (!_realImageContainer) {
_realImageContainer = [UIImageView new];
[self addSubview:_realImageContainer];
[_realImageContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
return _realImageContainer;
}
#end
When you want to make the image masked and shadowed, you can set image in realImageContainer and set mask to realImageContainer layer,so you get the masked layer.
NEWImageView *newImgView = [[NEWImageView alloc] init];
newImgView.backgroundColor = [UIColor clearColor];
newImgView.contentMode = UIViewContentModeScaleAspectFit;
newImgView.realImageContainer.image = self.image;
newImgView.realImageContainer.layer.mask = self.maskLayer;//this masklayer you can make youself
What about shadow?Because the realImageContainer is added to NEWImageView's view,the NEWImageView's layer not used yet,you can set shadow here.
newImgView.layer.shadowColor = [UIColor blackColor].CGColor;
newImgView.layer.shadowOpacity = 0.33;
newImgView.layer.shadowRadius = 8;
newImgView.layer.shadowOffset = CGSizeMake(0, 19);
so you get a masked and shadowed image.(I use a triangle image as mask,so I get this image)
you have to set an image with a transparent background and then you add the shadow like that:
imageView.layer.shadowColor = [UIColor blackColor].CGColor;
imageView.layer.shadowOpacity = 0.1;
imageView.layer.shadowRadius = 5;
imageView.layer.shadowOffset = CGSizeMake(5, 5);
[imageView setClipsToBounds:NO];
remember you have to import QuarzCore library

Mask a view in Objective-C

In ActionScript 3 we can apply a mask of to a visual object like this:
SomeVisualObject.mask = maskShapeObject;
How can I achieve similar result in Objective-C? Assume I have two UIImageView objects, I want something like this:
imageView1.mask = imageView2;
How can I use one UIImageView to mask, or clip the shape of, another?
CALayer *maskLayer = [CALayer layer];
UIImage *maskImage = [UIImage imageNamed:#"maskImage.png"];
maskLayer.contents = (id)maskImage.CGImage;
maskLayer.bounds = (CGRect){CGPointZero, maskImage.size};
UIImageView *imageViewToMask = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
imageViewToMask.image = [UIImage imageNamed:#"image2.png"];
imageViewToMask.layer.mask = maskLayer;

How to add only right border to UIImageView

I want to add a white border to an UIImageView. I tried the following, but it didn't work:
UIImage *image = [UIImage imageNamed:imagePath];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.width = rect.size.width + 1; // create white right border
[imageView setBackgroundColor:[UIColor whiteColor]];
imageView.frame = rect;
[myViewView addSubview:imageView];
I now did it like
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor whiteColor].CGColor;
sublayer.frame = CGRectMake(imageView.bounds.size.width, 0, 1, imageView.frame.size.height);
[imageView.layer addSublayer:sublayer];
You can create a UIView that is larger than the UIImage view, and set the image view's frame to be 0,0, width+1, height, and that will add the extra to the side.

Resources