第一种:设置CALayer的cornerRadius 注意:ios9.0之后对UIImageView的圆角设置做了优化,UIImageView这样设置圆角 不会触发离屏渲染,ios9.0之前还是会触发离屏渲染。而UIButton还是都会触发离屏渲染。
第二种:shouldRasterize=YES设置光栅化 通过Core Graphics重新绘制带圆角的视图 这种方式性能最好,但是UIButton上不知道怎么绘制,可以用UIimageView添加个 点击手势当做UIButton使用
#import "ViewController.h"
#import "CornerRadiusCell.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"查看字体集";
[self.view addSubview:self.tableView];
}
#pragma mark - lazy
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.rowHeight = 80;
_tableView.estimatedRowHeight = 0.0;
_tableView.sectionHeaderHeight = 0.0;
_tableView.sectionFooterHeight = 0.0;
_tableView.estimatedSectionHeaderHeight = 0.0;
_tableView.estimatedSectionFooterHeight = 0.0;
[_tableView registerClass:[CornerRadiusCell class] forCellReuseIdentifier:NSStringFromClass([CornerRadiusCell class])];
}
return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CornerRadiusCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([CornerRadiusCell class])];
return cell;
}
@end