---
title: "转：实现UIView圆角"
author: "chenjohney"
date: "2011-12-14T22:49:40Z"
tags: ["View圆角", "iOS"]
categories: ["移动开发"]
slug: "uiview"
draft: false
lastmod: "2011-12-14T22:49:40Z"
id: 1310997
url: "https://chenjohney.iteye.com/blog/1310997"
---

具体的实现是使用QuartzCore库，下面我具体的描述一下实现过程：

- 首先创建一个项目，名字叫：ipad\_webwiew
- 利用Interface Builder添加一个UIWebView，然后和相应的代码相关联
- 添加QuartzCore.framework

 

    代码实现：

头文件：

    #import &lt;UIKit/UIKit.h&gt;  
    #import &lt;QuartzCore/QuartzCore.h&gt;  
    @interface ipad\_webwiewViewController : UIViewController {  
        IBOutlet UIWebView \*myWebView;  
        UIView \*myView;

    }  
    @property (nonatomic,retain) UIWebView \*myWebView;  
    @end

代码实现：

 

```
   - (void)viewDidLoad {
        [super viewDidLoad];
        //给图层添加背景图片：
        //myView.layer.contents = (id)[UIImage imageNamed:@"view_BG.png"].CGImage;
        //将图层的边框设置为圆脚
        myWebView.layer.cornerRadius = 8;
        myWebView.layer.masksToBounds = YES;
        //给图层添加一个有色边框
        myWebView.layer.borderWidth = 5;
        myWebView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor];
    }
```