是否可以制作圆角(topLeft 和 topRight)来自动调整uiview?这是我的代码:
SFDetailViewController.h
@interface SFDetailViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, PopoverViewListDelegate>
{
...
UIView *header;
}
@property (nonatomic, retain) IBOutlet UIView *header;
@end
SFDetailViewController.m
#import "SFDetailViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface SFDetailViewController ()
@end
@implementation SFDetailViewController
@syntesyze header;
-(void) viewDidLoad
{
....
[self setCornerRadiusToHeader:header];
}
-(void) setCornerRadiusToHeader:(UIView *)headerView
{
CGRect bounds = headerView.layer.bounds;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
cornerRadii:CGSizeMake(8.0, 8.0)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = bounds;
maskLayer.path = maskPath.CGPath;
[headerView.layer addSublayer:maskLayer];
headerView.layer.mask = maskLayer;
}
该视图在 IB 中定义为:
我得到的 - 右上角是直的,因为视图的大小是动态的。