UIView/UIButton 设置圆角

来源:互联网 发布:cba球员卧推数据 编辑:程序博客网 时间:2024/05/10 04:17
转自 http://www.cocoachina.com/bbs/read.php?tid=65632&keyword=Բ��


UIImageView *v=[[UIImageView alloc] initWithFrame:CGRectMake(25, 25, 100, 100)];
    v.image=[UIImage imageNamed:@"face01.png"];
    [[v layer] setBorderWidth:2.0];//画线的宽度
    [[v layer] setBorderColor:[UIColor blackColor].CGColor];//颜色
    [[v layer]setCornerRadius:15.0];//圆角
    v.backgroundColor=[UIColor redColor];
    
    
    //[v.layer setCornerRadius:8.0];
    [v.layer setMasksToBounds:YES];
    [self.view addSubview:v];
    
    [v release];


还有一种更简便的方法
--------------------------------
其实,这件事情没有这么复杂的。
只需要加两句话就够了:
这里给个例子吧:
    UIButton * takepicbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    takepicbtn.frame = CGRectMake(320-50, 250-50, 50, 50);
加下面两句话:
    takepicbtn.layer.cornerRadius = 50/2;/////////////////////////自己试着改变这个值,看看各个不同的效果。现在的设置是画了个圆圈。
    takepicbtn.layer.masksToBounds = YES;//////////////////////////

仔细看了下,楼主其实就是这个方法。//shy
0 0
原创粉丝点击