IOS设置UIView的边框为圆角

来源:互联网 发布:获取基址的文本源码 编辑:程序博客网 时间:2024/06/06 12:57
 iOS 系统自带的 View 组件都是正方形的,看起来都太生硬,有时候我需要变成圆角形式,如下图:

    具体的实现是使用QuartzCore库,下面我具体的描述一下实现过程:
    •    首先创建一个项目,名字叫:ipad_webwiew
    •    利用Interface Builder添加一个UIWebView,然后和相应的代码相关联
    •    添加QuartzCore.framework

    代码实现:
头文件:
  
[java] view plaincopy
  1. #import <UIKit/UIKit.h>
      
  2. #import <QuartzCore/QuartzCore.h>
   
  3.      
  4. @interface ipad_webwiewViewController : UIViewController   
  5. {
          
  6. IBOutlet UIWebView *myWebView;
     
  7. UIView *myView;

      
  8. }
      
  9. @property (nonatomic,retain) UIWebView *myWebView;
      
  10. @end  
  11. 代码实现:  
  12.     - (void)viewDidLoad   
  13. {
         
  14.  [super viewDidLoad];
      
  15.     //给图层添加背景图片:
         
  16.  //myView.layer.contents = (id)[UIImage imageNamed:@"view_BG.png"].CGImage;
          
  17. //将图层的边框设置为圆脚
  
  18. myWebView.layer.cornerRadius = 8;
   
  19. myWebView.layer.masksToBounds = YES;  
  20. //给图层添加一个有色边框
         
  21.  myWebView.layer.borderWidth = 5;
          
  22. myWebView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor];
      
  23. }  
0 0
原创粉丝点击