UIView的圆角

在开发中经常遇到要设置UIView,UIbutton等圆角,经常给那些控件添加一个UIImageView作为背景,再加载圆角图片很麻烦,下面简单的方法实现。

view.layer.cornerRadius = 10;//设置那个圆角的半径

view.layer.borderWidth = 10;//设置边框的宽度,也可以不设置

view.layer.borderColor = [[UIColor redColor] CGColor];//设置边框的颜色

view.layer.masksToBounds = YES;

再比如Button

  UIButton *submitButton = [UIButton buttonWithType:UIButtonTypeCustom];

    submitButton.frame = CGRectMake(10, headView.frame.size.height+headView.frame.origin.y+15, 300, 40);

    submitButton.layer.cornerRadius = 2.0;

    submitButton.layer.masksToBounds = YES;


最后别忘记添加QuartzCore.framework这个库,还有在你的文件中包含#import <QuartzCore/QuartzCore.h>

你可能感兴趣的:(UIView的圆角)