6.1-CALayer 使用

@设置圆角

  1UIView圆角

    <1直接操作其仅有的图层即可:iconView.layer.cornerRadius =10;

  2UIImageView圆角

    <2// 设置圆角半径

    self.imageView.layer.cornerRadius = self.imageView.frame.size.width * 0.5;

    // 超出图层范围的内容裁决掉

    self.imageView.layer.masksToBounds = YES;

  3UIButton圆角

   

   // 设置圆角半径

    self.button.imageView.layer.cornerRadius = self.button.frame.size.width *0.5;

  // 超出图层范围的内容裁决掉

    self.button.imageView.layer.masksToBounds = YES;

4自定义控件

   同上1

注意点

1圆角效果,并不是在给定frame布局后有,要给定内容后才有

    

        //头像
        NSData *data = [[DJXMPPTool sharedInstance].cardAvatarModule photoDataForJID:jid];
        UIImage *iconImg = [UIImage imageWithData:data];
        [self.iconBtn setImage:iconImg forState:(UIControlStateNormal)];
        //圆角
        [_iconBtn setCornerRadiusToCircle];
原文地址:https://www.cnblogs.com/dzq1991/p/6251372.html