How to get rid of the black around my UIImage? (shown in link below)
UIView *myView = [[[UIView alloc] init] autorelease];
[myView setBackgroundColor:[UIColor clearColor]];
CCUIViewWrapper *wrapper = [CCUIViewWrapper wrapperForUIView:myView];
UIColor *background = [UIColor colorWithPatternImage:[UIImage imageNamed:#"alert_background.png"]];
myView.backgroundColor = background;
wrapper.contentSize = CGSizeMake(293,180);
wrapper.position = ccp(-90,190);
[wrapper setRotation:90.0];
[self addChild:wrapper];
http://img857.imageshack.us/i/screenshot20110312at153.png/
try setting the opaque value of the view to NO
myView.opaque = NO;
This means that the view isn't expected to fill its bounds.
nonono
Related
I would like to show a small icon next to the title in my UINavigationController.
Through the magic of Photoshop, like this:
I know I need to create a new view and build the image and title into it. Here is what I am doing:
In viewDidLoad in the UINavigationController view controller, I call the method
[self setTitleBar];
Which calls this method:
- (void) setTitleBar {
CGRect navBarFrame = self.navigationController.navigationBar.frame;
//UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(navBarFrame.origin.x, navBarFrame.origin.y, (leftButtonFrame.origin.x + leftButtonFrame.size.width) - rightButtonFrame.origin.x, navBarFrame.size.height)];
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(navBarFrame.origin.x, navBarFrame.origin.y,self.view.frame.size.width,navBarFrame.size.height)];
titleView.backgroundColor = [UIColor clearColor];
CGPoint tvCenter = CGPointMake(titleView.frame.size.width/2, titleView.frame.size.height/2);
UIImage * icon = [UIImage imageNamed:#"star"];
UIImageView *iconView = [[UIImageView alloc] initWithImage:icon];
iconView.frame = CGRectMake(0, 0, icon.size.width, icon.size.height);
UILabel *title = [[UILabel alloc] init];
title.backgroundColor = [UIColor clearColor];
title.textColor = [UIColor whiteColor];
title.textAlignment = NSTextAlignmentCenter;
title.text = #"SOME TITLE";
title.frame = CGRectMake(0, 0, 100, titleView.frame.size.height);
[title sizeToFit];
iconView.center = CGPointMake(tvCenter.x - (icon.size.width/2), tvCenter.y);
[titleView addSubview:iconView];
[titleView addSubview:title];
self.navigationItem.titleView = titleView;
}
My logic in the titleView is: Get the left most button's frame and get the right most buttons frame. THEN do some math to figure out how big the view can be. That should be the titleView's frame size.
However, I can't seem to get it to work. If I plug in a frame size of 0,0,100,40; then it shows the frame but everything is squished together. But you see it. I know that 100 should be dynamic to ensure that the title is shown.
But I can't seem to figure it out.
Any help?
You can place objects on the Navigation Controller View, as subviews.
- (void) setTitleBar {
//Let's say your icon size is 20
int starSize = 20;
//Now you'll have to calculate where to place the ImageView respect the TextSize (for this you'll need to know the text and font of your UINavigationItem title)
CGSize textSize = [#"SOME TITLE" sizeWithAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"navfontname" size:15]}];
UIImageView *startImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.navigationController.view.frame.size.width/2 - textSize.width/2, self.navigationController.view.frame.size.height/2 - starSize/2, starSize,starSize)];
startImageView.image = [UIImage imageNamed:#"star"];
[self.navigationController.view addSubview:startImageView];
}
I have a UIImageView and this is my code to show image :
callRecImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"call_accept.png"]];
[callRecImage setFrame:CGRectMake(133,top, 36, 40)];
[self.view addSubview: callRecImage];
To add circle around image I did this :
callRecImage.layer.cornerRadius = callRecImage.frame.size.width /2; callRecImage.layer.borderWidth = 2.0f;
callRecImage.layer.borderColor = [UIColor grayColor].CGColor; callRecImage.clipsToBounds = YES;
my image view is :
my output is :
I want to add a circle to my UIImageView, I have followed this link image in circle frame iOS but it's working as I expected
I want a big circle around the phone image. any kind of help will be appreciated.
Thanks in advance
[callRecImage setFrame:CGRectMake(133,top, 36, 40)];
//Set Height and width equal
//Like
[callRecImage setFrame:CGRectMake(133,top, 40, 40)];
use the following code
#import <QuartzCore/QuartzCore.h>
callRecImage.layer.masksToBounds = YES;
callRecImage.layer.cornerRadius = callRecImage.bounds.size.width/2;
callRecImage.layer.borderWidth = 2.0f;
callRecImage.layer.borderColor = [UIColor grayColor].CGColor;
Add the below line to fill you image in ImageView only
callRecImage.contentMode = UIViewContentModeScaleAspectFill;
Try this code
callRecImage.layer.backgroundColor=[[UIColor clearColor] CGColor];
callRecImage.layer.cornerRadius=20;
callRecImage.layer.borderWidth=2.0;
callRecImage.layer.masksToBounds = YES;
callRecImage.layer.borderColor=[[UIColor grayColor] CGColor]
Whenever you go for layer.cornerRadius for the same view then circle will be always smaller then the view rectangle so use one of these two solution.
I have tested and both the solutions are in working condition
Use following code to change UIViewContentMode of your image and increase your UIImageView frame size (height and width, both should be in equal)
callRecImage.contentMode = UIViewContentModeCenter;
So that if you increase the UIImageView frame size, It will keep your image in center and won't stretch your image inside UIImageView
UIImageView *callRecImage = [[UIImageView alloc] initWithFrame:CGRectMake(133, top, 60, 60)];
callRecImage.contentMode = UIViewContentModeCenter;
[callRecImage setImage:[UIImage imageNamed:#"call_accept.png"]];
callRecImage.layer.cornerRadius = callRecImage.frame.size.width /2;
callRecImage.layer.borderWidth = 2.0f;
callRecImage.layer.borderColor = [UIColor grayColor].CGColor;
callRecImage.clipsToBounds = YES;
[self.view addSubview: callRecImage];
or
Add one UIView as superview of your UIImageView and add layer.cornerRadius to that UIView
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(133, top, 60, 60)];
UIImageView *callRecImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"call_accept.png"]];
[callRecImage setFrame:CGRectMake(view.frame.size.width/2 - 36/2, view.frame.size.height/2 - 40/2, 36, 40)];
view.layer.cornerRadius = view.frame.size.width /2;
view.layer.borderWidth = 2.0f;
view.layer.borderColor = [UIColor grayColor].CGColor;
view.clipsToBounds = YES;
[view addSubview: callRecImage];
[self.view addSubview: view];
I'm trying to size an MKMapView in the following way:
Elements should be able to appear behind the arc at the top, so it appears that the view is not square. I know this should be possible with CALayer, but perhaps someone has done it before?
This should be quite possible if you put your MKMapView within a UIView, then apply a mask to that.
Here's a very (!) basic example:
All I've done is put my map in a UIView called "mapContainer" and added a mask to it using this:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect rect = CGRectInset(self.view.frame, 70, 70);
UIView* newView = [[UIView alloc] initWithFrame:rect];
newView.layer.cornerRadius = 55.0;
newView.backgroundColor = [UIColor redColor];
self.mapContainer.layer.mask = newView.layer;
}
And you could add a border to it...
..with a few more lines...
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect rect = CGRectInset(self.view.frame, 70, 70);
UIView* newView = [[UIView alloc] initWithFrame:rect];
newView.layer.cornerRadius = 55.0;
newView.backgroundColor = [UIColor redColor];
UIView* borderView = [[UIView alloc] initWithFrame:rect];
borderView.backgroundColor = [UIColor clearColor];
borderView.layer.cornerRadius = 55.0;
borderView.layer.borderWidth = 3.0;
borderView.layer.borderColor = [[UIColor redColor] CGColor];
[self.mapContainer addSubview:borderView];
[self.mapContainer bringSubviewToFront:borderView];
self.mapContainer.layer.mask = newView.layer;
}
I hope this points you in the right direction.
Unlike Apple Maps.
;-)
Please check below image.
If you see, below the black outline of the blue speech bubble, there is a skybluish portion shown.
I am using a transparent png for the blue speech bubble. So, not sure from where this skyblue portion comes.
Please is the transparent PNG of the speech bubble that I use.
What is wrong here?
UIView* popoverView1;
UIViewController* popoverContent;
UIImageView *imagebackground;
#property (nonatomic,retain) IBOutlet UIPopoverController *pc;
popoverContent = [[UIViewController alloc]init];
popoverView1 = [[UIView alloc]initWithFrame:CGRectMake(56,0,393,444)];
// popoverView1.backgroundColor = [UIColor whiteColor];
imagebackground = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,393,444)];
[imagebackground setImage:[UIImage imageNamed:#"card-creation-screen15.png"]];
[popoverView1 addSubview:btndone];
[popoverView1 addSubview:btn];
popoverContent.view = popoverView1;
[btndone setHidden:YES];
[popoverView1 addSubview:imagebackground];
[popoverView1 bringSubviewToFront:btn];
[popoverView1 bringSubviewToFront:btndone];
popoverController.backgroundColor = [UIColor clearColor];
popoverView1.backgroundColor = [UIColor clearColor];
popoverContent.contentSizeForViewInPopover = CGSizeMake(393, 444);
pc = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[pc presentPopoverFromRect:CGRectMake(20,650,131,131) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
pc.backgroundColor = [UIColor clearColor];
popoverController.backgroundColor = [UIColor clearColor];
popoverView1.backgroundColor = [UIColor clearColor];
pc.backgroundColor = [UIColor clearColor];
Your popoverview1 view has a white backgroundColor, that should be [UIColor clearColor]; in any case - you also see a small white border on top of your image because of that. Where the gradient comes from I can't explain from the information you gave.
I want to build a totally transparent view, the backgroundColor maybe clearColor. Inside this view I want to put a small image. And in the four sides of this transparent view, I want to see the effect of shadow. The shadow must be totally outside the view. I know that I must override the drawRect method in UIView, but don't know how to do this.
try this....
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(50.0, 100.0, 100.0, 100.0)];
shadowView.layer.cornerRadius = 15.0;
CALayer *layer = shadowView.layer;
layer.shadowOpacity = 1.0;
layer.shadowColor = [[UIColor blackColor] CGColor];
layer.shadowOffset = CGSizeMake(0,0);
layer.shadowRadius = 15;
[self.view addSubview:shadowView];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 50.0)];
[imageView setImage:[UIImage imageNamed:#"icon.png"]];
[shadowView addSubview:imageView];
What is the problem with doing something like this?
#import <QuartzCore/QuartzCore.h> // at the top of the file
UIView *transparentView = [[UIView alloc] initWithFrame:CGRectMake(50,50,200,200)];
transparentView.backgroundColor = [UIColor greenColor];
transparentView.alpha = 0.5f;
transparentView.clipsToBounds = NO;
transparentView.layer.shadowColor = [UIColor blackColor].CGColor;
transparentView.layer.shadowOpacity = 1;
transparentView.layer.shadowRadius = 1;
UIImageView *imageView = [[]UIImageView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];
imageView.image = [UIImage imageNamed:#"IMAGE NAME"];
[transparentView addSubview:imageView];
As you can see, based on your description, no drawRect: required, unless for some reason you want to draw the shadow manually, but there isn't a reason to.