How to make shadow in UILabel - xcode

Shadow of UILabel"
I have tried this code
label.shadowColor = [UIColor blackColor];
label.shadowOffset = CGSizeMake(1.0, 1.0);
but i am unable to get the shadow, i have searched on the internet, but none answers well.
http://tinyurl.com/au4exlo , this is a reference site, where a shadow is there under each word.
Please correct my code if am wrong.
Thanks

I think these are two separate UILabels displaying same values but one is inverted. Additionally, the bottom UILabel is obscured by a half transparent PNG image.
If you are not familiar with Photoshop, This might give you idea about what I mean by half transparent gradient. http://thepowerpointblog.com/media/blogs/all/10_Sept/Lance_8.jpg

Related

NSImage is always being scaled and looks bad

I want to create an NSImage of an NSScrollView object, so I can use the flat graphic for animation purposes.
When I render my scrollview object into a graphic and add it back to my window, it works but looks really bad like it's been scaled to 99% or something. I want the image to not be scaled and 100% pixel accurate. (Note: the image isn't scaled, it's the same size, it just looks like it's been poorly rescaled - the text looks rough and poor compared to the view onscreen in the scrollview)
My code:
(scrollView is my NSScrollView object)
NSData *pdf = [scrollView dataWithPDFInsideRect:[scrollView bounds]];
NSImage *image = [[NSImage alloc] initWithData:pdf];
NSImageView *imageView = [[NSImageView alloc] initWithFrame:[scrollView bounds]];
[imageView setImage: image];
[mainGUIPanel addSubview: imageView];
I've tried a heap of things, messed with pixel sizes, bounds, used IB to create the destination NSView and put the image inside that but just cannot get the image to not look bad. Any ideas?
Edit:
I tried writing the pdf data to a pdf file and viewed it, and it looked ok. So the bitmap image is being captured ok, it's just on the display that it looks like it's being scaled somewhat.
Edit2:
Also tried getting the bitmap like this:
NSBitmapImageRep *bitmap = [scrollView bitmapImageRepForCachingDisplayInRect:[scrollView bounds]];
[scrollView cacheDisplayInRect:[scrollView bounds] toBitmapImageRep:bitmap];
NSImage * image = [[NSImage alloc] initWithSize:[bitmap size]];
[image addRepresentation: bitmap];
Same results - the bitmap looks exactly the same, bad and scaled when displayed.
This leads me to believe that capturing the bitmap data either way works fine, it's creating the view and rendering the image that is doing the scaling. How can I make sure that the view and image are shown at the correct size and scaling?
Edit3:
Ok, I started a new blank project and set this up, and it works perfectly - the new imageview is identical to the grabbed bitmap. So I suspect my issue is stemming from some rendering/compositing issue when drawing the bitmap to the view. Investigating further...
It turns out the issue stems from the scrollView that I am rendering from. This has a transparent background (Draw Background is off in IB) and the text is the scrollView looks good. If I turn "Draw Background ON", with a transparent background color, the text is rendered badly, exactly as it is when I capture the image programatically.
So, in my app, even though Draw Background is off, the scrollView image is captured as though Draw Background is on. So I need to understand why the text is rendered badly when Draw Background is on and set to transparent, and hopefully this will lead me towards a solution.
Also tried creating an NSClipview with background drawing turned off and putting the bitmap view into that, but it sill renders the same. I can't find a way to render the transparent image to the screen without horrible artifacting.
Ok, I've found a solution. Instead of getting a grab of the transparent background scrollview object itself, I'm instead getting a grab of the parent view (essentially the window background), and restricting the bounds to the size of the scrollview object.
This captures both the background, and the contents of the scrollview, and displays correctly without any issues of transparency.

Displaying landscape images from camera roll xcode

I'm pulling images from the camera roll to display in my app, and portrait taken pictures work just fine, but landscape images get all funky smushed together.
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
displayPhoto.image = image;
I've figured out how to check the length and width of the pictures themselves, and therefore can do an if else statement to only rotate landscape pictures... but trying to find working code to actually rotate the images is difficult. I found an answer here, but he's calling functions that don't exist, and clearly the code did not work for me :p. Any assistance would be greatly appreciated. Thanks.
u have to use
[displayPhoto setContentMode:UIViewContentModeScaleAspectFit];

How to make UIImage rounded,Not rounded corner

Draw a circle,make a rounded UIImageView in it.How to get this, please guide me.
thx!
Let's put it this way,
First we create a UIImageView to the size of the circle you want.Let's say you want this image to be a circular image,
http://united4iran.org/wp-content/uploads/2010/11/cell-phone-in-canada.jpg
Then you create another UIImageView one top of the previous one to the size of 320x480 and set this image to it (Assume this image size is 320x480),
Note: also remember that inner area of the circle in above image is transparent.
Then you should get a image like this,
http://img580.imageshack.us/img580/782/testjkn.png
Hope this will help you.

Blurry NSImageView

I have an NSImageView in a view that utilizes Core Animation. Prior to using Core Animation the image looks fine but now its blurry and low quality. If I let NSImageView have a bezel border the issue goes away but I need it to have no border. Had this happened to anyone else?
Imgae in the background with no border, same image in the front with a border.
Thanks
EDIT: I forgot to mention that the image is an icon file (ICNS) so it has various sizes. The bordered view loads the correct size and the transparent one loads the smallest and stretches it.
Although not the way I wanted to, I managed to create a fix for the issue. The issue seemed to be the way that NSImageView was drawing the image so I created a custom NSView subclass with support for the same bindings I used in my original image view. Im not sure why the blurry-ness happend in the beginning, but drawing the image by hand in an NSView seems to do the trick.
Your image may be drawing in a non-pixel-aligned way. Have you tried shifting it by a half pixel?
Apple has a good demonstration of this in the BlurryView app in their "Cocoa Tips and Tricks" sample code.
Cocoa Tips and Tricks

colorWithPatternImage creates black grids in iphone 4

I have
UIView *topPart = [[UIView alloc] initWithFrame:CGRectMake(9, 0, 302, 318)];
topPart.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"pattern.png"]];
[someScroller addSubview:topPart];
[topPart release];
and I can see the pattern fine when I use a 3gs or the iphone simulator, but when I tested on an actual iPhone 4, I see the pattern images but there are black lines separating each pattern so it looks like a grid. I checked the pattern image and there is no black border or anything .
There was someone with a different problem but it may be the same solution
colorWithPatternImage with iPhone 4 Retina Display (image#2x.png)
but they suggested using the -(void)drawRect: method, only problem is i have no idea how to do that.
Thanks
I was experiencing the same issue and found it was due to my png being greyscale (not RGB)
To check if this is the case, just select the image in Xcode, show the Utilities sidebar (the one that appears from the right) and look at the Color Space.
To fix this you can use your favourite image editor, but for photoshop do this:
Open the greyscale image
Select all and copy
Create a new document (but this time make sure the colour space is RGB)
Paste
Hope it helps :)
I figured it out by combining the answers from these 2 posts
https://devforums.apple.com/message/259150#259150
How can I use CGContextDrawTiledImage to tile an image?
UIImage *thePattern= [self GetFineTiles:[UIImage imageNamed:#"Feedbackpattern.png"]];
theView.backgroundColor = [UIColor colorWithPatternImage:thePattern];
-(UIImage*)GetFineTiles:(UIImage*)badImage{
UIGraphicsBeginImageContext(badImage.size);
CGContextRef imageContext = UIGraphicsGetCurrentContext();
CGContextDrawTiledImage(imageContext, (CGRect){CGPointZero,badImage.size}, badImage.CGImage);
UIImage *goodPattern = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return goodPattern;
}
Hope this helps others

Resources