How to make Custom UIview which have rounded corne

2019-10-02 15:04发布

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.

4条回答
神经病院院长
2楼-- · 2019-10-02 15:17

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...

查看更多
来,给爷笑一个
3楼-- · 2019-10-02 15:22

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

查看更多
做自己的国王
4楼-- · 2019-10-02 15:26

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];
查看更多
劫难
5楼-- · 2019-10-02 15:32

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.

查看更多
登录 后发表回答