Atchu Chitri
Atchu Chitri

Reputation: 11

How to set round corners in UI images in iphone

I am trying to develop an iPhone application to set the UI Image.

Upvotes: 0

Views: 2551

Answers (7)

Krishnabhadra
Krishnabhadra

Reputation: 34275

You can use cornerRadius property

yourImageView.layer.cornerRadius = 5.0;  //change value for your need

Upvotes: 0

VRN
VRN

Reputation: 13

You need QuartzCore framework for this.

  • Import QuartzCore Framwork
  • Add #import <QuartzCore/QuartzCore.h> to your .h file

then use

UIImageView *imgViw = [[UIImageView alloc] initWithImage:img];
imgViw.layer.cornerRadius = 10.0f;
imgViw.layer.borderWidth = 1.0;//For border

Upvotes: 0

GameLoading
GameLoading

Reputation: 6708

Get the layer of camBtn.

Setimage to that layer.

Add cornerradious to that layer.

The camBtn should be custombutton

//layer work

UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];

Upvotes: 1

oOEric
oOEric

Reputation: 1079

UIImageView *pic = [[UIImageView alloc] initWithImage: ...];
pic.layer.cornerRadius = 7.0f;
pic.layer.masksToBounds = YES;

Upvotes: 0

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

use below code.

CALayer * l = [camBtn layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];

Upvotes: 1

Bourne
Bourne

Reputation: 10312

set the proper radius value for this: UIImageView -> layer -> cornerRadius

Be sure to include QuartzCore.h

UIImageView* imgView = [[UIImageView alloc] initWithImage:image];
imgView.layer.cornerRadius = 15.0;

Where image is the image you wish to show. Display the above imageView to get the rounded effect

Upvotes: 0

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

You could not set the corner of UIImage instance because it's not inherited from UIView, So you need to create an UIImageView instance by passing your UIImage.

use the below code.

UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];

Upvotes: 4

Related Questions