How to make Custom UIview which have rounded corne

2019-10-02 14:46发布

问题:

I want to make Custom UIview which have rounded cornes.

Is this possible? I have no idea how to do this.

Any suggestions from experts will be welcome.

回答1:

For this you need to import Quartz famework..You can also set Bordercolor,shadow color,corner width,etc to that view

#import <QuartzCore/QuartzCore.h>

And try this code.

        [self.YourView.layer setCornerRadius:1.0];
        [self.YourView.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
        [self.YourView.layer setBorderWidth:1.0];
        [self.YourView.layer setShadowColor:[UIColor lightGrayColor].CGColor];


回答2:

Add This Framwork

#import "QuartzCore/QuartzCore.h" 


UIView *view = [[UIView alloc] initWithFrame:CGRectMake("As You Need")];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 15.f; // set as u need
    view.layer.borderColor = [UIColor grayColor].CGColor; // set color as u need
    view.layer.borderWidth = 2.f; // set as u need

This code might helpful for you.



回答3:

First add QuartzCore Framework to your project.

Then import it into your class where you want to set your view corner radius,

#import <QuartzCore/QuartzCore.h>

Now make an IBOutlet in .h file to UIView (Assuming added by you in your XIB)

    IBOutlet UIView *backViewGroupName;

In your .m file,set sorner radius to your view

backViewGroupName.layer.cornerRadius=10.0;

Hope it helps...



回答4:

Import the QuartzCore Framework

#import <QuartzCore/QuartzCore.h>

then do this

View.layer.borderWidth = 3;
View.layer.cornerRadius = 10;
View.layer.masksToBounds = YES;

Dont forget masks to bound = yes. Hope this helps. Happy Coding