Preview rounded image in iphone - iphone

can anyone tell me how can I create an image preview inside a customized cell with the aspect of the ones loaded in the mms'.
I've been trying to do it by changing values in IB and I haven't been able to.
Thanks a lot!
(source: iphonehelp.in)
Thanks for the three answers.
Doing
cell3.imageView.layer.masksToBounds = YES;
cell3.imageView.layer.cornerRadius = 16;
cell3.imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
cell3.imageView.layer.borderWidth = 1.0;
I was able to do part of what I want. However, I still can't put that "glow" look on the image. Does anybody now which property should I control?
Thanks a lot (and thanks again).

Sure. Add the QuartzCore framework to your project, then:
#import <QuartzCore/QuartzCore.h>
// ...
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 4;
Note that the cornerRadius property is only available in OS 3.0 and later; if you're supporting an older version (which you probably don't have to be), you'll need to do some Core Graphics work.

will creating an image in an image editor and then setting it as the cell's background not work?
This might be useful for you
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

If your image is in an image view and you're targeting OS 3.0+, you can set imageView.layer.cornerRadius.

Related

How to use rounded corner label in iphone, UILabel Round Corners

I am using some labels in a view. I want to make rounded corner label in my iphone application. I use following code to do this but it's not work. I got have some errors to use that properties.
label.layer.borderColor = [UIColor blueColor].CGColor;
label.layer.borderWidth = 4.0;
label.layer.cornerRadius = 8;
I was facing the same problem, using a UILabel with backgroundColor in a cell, and added this to work correctly :
label.layer.cornerRadius=8.0;
label.clipsToBounds=YES;
Just add #import <QuartzCore/QuartzCore.h> in your .m file
and suppose you have a UILabel *myLabel;
just do [myLabel.layer setCornerRadius:20]; //value '20' can be changed according to your wish :)
Hard to know for sure what you're asking as you didn't include the errors you're getting. Have you added the QuartzCore framework to your project and #import <QuartzCore/CALayer.h> to the file modifying the layer? If that's not it, add the errors and more info to your question.
EDIT: you can also #import <QuartzCore/QuartzCore.h> as suggested in the comments. QuartzCore.h includes CALayer.h along with the rest of the QuartzCore components.
This simple code enough for RoundLabel
LabelName.layer.cornerRadius = LableName.frame.size.height/2;
LabelName.layer.masksToBounds = YES;
I would create a view with rounded corners and add the label to that view.

Contact image composition like Contacts app

I'm trying to replicate how the Contacts app shows user pictures in my own app, but am at a loss as to how they went about it.
Here's how there's looks...
...and (I assume) they are using a combination of these images (from the AddressBookUI framework) to accomplish it...
...but I'm not sure how. Most methods I've tried require an image without an alpha channel, yet their image marked "mask" (middle one) has an alpha channel. I've also tried other masking methods that just mask out a color but that doesn't seem to be the route they take.
Any insight into this?
I don't think they are combining any images. They are probably doing something like this:
imageView.layer.cornerRadius = 5;
imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
imageView.layer.borderWidth = 3;
imageView.layer.masksToBounds = YES;
And then you can just set the the image of the imageView normally (imageView.image = [UIImage imageName:#"person.png"];)

TTPhotoViewController: deactivate gallery auto zoom

In my project, I use the Facebook API "three20": https://github.com/facebook/three20/
Now, I need to customize the TTPhotoViewController.
In the gallery, there's an "auto zoom". The complete width and height are always used:
The disadvantage is that you can not see the complete photo and important information could be cut off / cropped.
How can I deactivate the automatic zoom?
Thanks!
EDIT 03-Mar-2011:
Roman's answer seems to be good, but unfortunately it doesn't helps me. Yes, the content mode UIViewContentModeScaleAspectFill is the problem:
Scales the content to fill the size of
the view. Some portion of the content
may be clipped to fill the view’s
bounds.
But there's no other content mode that solves my problem. I think, I have to look deep inside three20 and scale the images by myself. But I need your help to do this! So, I'll start a new "bounty" today (03/03/2011)...
Thank you very much!!
EDIT 07-Mar-2011:
Finally I got it!! roman's answer is right, I have to use UIViewContentModeScaleAspectFit.
The problem was: I use a wrong size in my Photo-Object! 320x480 worked for me:
NSMutableArray *photos = [NSMutableArray new];
for (Information *info in allImages) {
NSString *binaryId = info.binary;
NSString *fileName = [NSString stringWithFormat:#"documents://img/%#.jpg", binaryId];
Photo *photo = [[[Photo alloc] initWithCaption:info.name
urlLarge:fileName
urlSmall:fileName
urlThumb:fileName
size:CGSizeMake(320, 480)] autorelease];
[photos addObject:photo];
}
self.photoSource = [[PhotoSet alloc] initWithTitle:#"Photos" photos:photos];
easiest way is to hack TTPhotoView - around line 135 (function setImage) change
self.contentMode = UIViewContentModeScaleAspectFill;
to
self.contentMode = UIViewContentModeScaleAspectFit;
sadly there does not seem to be another way currently.
You should award your question to roman because he answers your specific question, but I want to suggest that you should consider not using three20 and implement your image scroller yourself. Take a look at Session 104, Designing Apps with Scroll Views (requires ADC login) from the WWDC 2010 session videos on iTunes. It walks you through exactly how to implement this type of interface and allows you to keep your app lean without having to add the entire three20 library to your code.
Make this change in TTScrollView class
In the method
- (CGRect)frameOfPageAtIndex:(NSInteger)pageIndex
In this method, change the following line
if (size.width > size.height) {
to
if (size.width / size.height > self.width / self.height) {
This worked for me.

Drawing shadow with Quartz is slow on iPhone & iPad. Another way?

I was pretty excited when I found out just how easy it is to add shadows to my UIViews on the iPhone/iPad.
Just add the framework in Xcode, add the import to the top of the file:
#import <QuartzCore/QuartzCore.h>
Then later:
self.contentView.layer.shadowRadius = 3.0;
self.contentView.layer.shadowOffset = CGSizeMake(-2.0, -3.0);
self.contentView.layer.shadowOpacity = 0.5;
self.contentView.layer.shadowColor = [UIColor blackColor].CGColor;
While this does create a beautiful shadow in my app, it also lags it to death now when the view is shown... even when launched outside of the debugger. Is there something I'm forgetting or is this method just not practical for larger views?
For reference, I posted a screenshot here.
You should set the shadowPath property. It is how CoreGraphics is able to optimize shadows.
For example, if your view is an opaque rectangle:
self.contentView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.contentView.bounds].CGPath;
Thought I should make an answer because I didn't want this gem to get buried in the comments.
In addition to cobbal's answer above, which helped a lot, occulus also mentioned the following optimization for non-rectangular shadows, such as text shadows.
self.contentView.layer.shouldRasterize = YES;
// Fix visual degradation when rasterizing on high-density screens:
self.contentView.layer.rasterizationScale = [[UIScreen mainScreen] scale];

Setting font of UILabel with Interface Builder comes out Helvetica

I'm having a problem setting the font for UILabels and UITextViews with Interface Builder.
I'm trying to set the font to Gill Sans.
If I set it programmatically it works fine, like this:
myLabel.font = [UIFont fontWithName:#"Gill Sans" size:24.0];
But if I try setting it with Interface Builder, I get the same behaviour described in this question here iPhone SDK: Interface Builder label font, only shows when editing label, but the Gill Sans is supposedly available on the iPad (and it is, since it works if I set it by code). And if I run it and do this:
NSLog(#"%#", myLabel.font.fontName);
it prints out "Helvetica".
Usually I wouldn't mind setting it programmatically, but the problem is that this particular class is used in several different places with different nib files to provide different layouts, so I can't have it hardcoded to always use the same font family. And subclassing it for each time it appears would be a huge pain, specially because I want to enable designers to create and change all the layout with interface builder whenever they want, and if they have to tell me what font they want every time so I can hardcode every particular case, that would be very awkward.
Has anyone experienced this problem before?
Maybe Interface Builder is limiting me to use the iPhone fonts even though the xib file's target is already set to iPad, but how do I convince it that I'm targeting the iPad?
Thanks in advance,
filipe
Ok, apparently this has been reported as a bug with IB 3.2.3:
https://devforums.apple.com/message/236134#236134
This guy says it used to work on 3.2.2, so I'll see if I can downgrade, or I'll just wait for a fix from Apple.
You can only use fonts that are present on the iPhone OS.
Check this answer for a way to embed custom fonts in your app.
Check out this post, if you do not want to create any IBOutlet.
https://stackoverflow.com/a/6620938/400909
Check out IBCustomFonts category I wrote:
https://github.com/deni2s/IBCustomFonts
IBCustomFonts category allows you to use custom fonts from Interface Builder (IB) when building your iOS apps.
Apps using IBCustomFonts category are approved by Apple App Store (as of September 2013).
No need to use IBOutlets, subclassing of UILabels and UIButtons or change fonts in code.
Tested on iOS6 and iOS7.
Cleaning all targets works few times. I had to quit IB and xcode to get the fonts in my last instance. I'm using xcode/IB 3.2.5 and I used chalkduster 13pt
HIH
If you use the subclassing UILabel approach and also want to keep the weight set in IB then use can do some thing like below. I couldn't find a better way to find out if the existing font is bold, italic or regular
- (void)awakeFromNib
{
[super awakeFromNib];
NSString *weight = [self.font.fontName substringFromIndex:[self.font.fontName length] - 5];
if ( [weight isEqualToString:#"-Bold"] )
{
self.font = [UIFont fontWithName:#"MyriadWebPro-Bold" size:self.font.pointSize];
}
else if ( [weight isEqualToString:#"-Italic"] )
{
self.font = [UIFont fontWithName:#"MyriadWebPro-Italic" size:self.font.pointSize];
}
else
{
self.font = [UIFont fontWithName:#"MyriadWebPro" size:self.font.pointSize];
}
}
I created a UILabel subclass that allows you to set a custom font in interface builder:
https://github.com/IntrepidPursuits/IPCustomFontLabel