[英]changing corner radius of uitableview grouped in iOS6
我嘗試使用下面的代碼,但沒有運氣。 有人知道如何在iOS 6中執行此操作嗎? 我不想創建一個自定義單元格。
self.tableView.layer.cornerRadius = 5.0f;
[self.tableView setClipsToBounds:YES];
編輯:
看來實際發生的是該代碼正在為整個視圖而不是每個UITableViewSection創建一個角半徑。 這有意義嗎?
我也嘗試過[cell.layer setCornerRadius:3.0];
但也沒有運氣 我的UITableView的角落仍然完全相同。
您可以更改TableViewCell的backgroundView,創建UIView的子類並更改圖層類:
@interface BackgroundView : UIView
@end
@implementation BackgroundView
+ (Class)layerClass
{
return [CAShapeLayer class];
}
@end
稍后在cellForRowAtIndexPath中,您將執行以下操作:
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
CGRect frame = cell.backgroundView.frame;
cell.backgroundView = [[BackgroundView alloc] initWithFrame:frame];
CGFloat corner = 20.0f;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:cell.backgroundView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(corner, corner)];
CAShapeLayer *shapeLayer = (CAShapeLayer *)cell.backgroundView.layer;
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = cell.textLabel.backgroundColor.CGColor;
shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
shapeLayer.lineWidth = 1.0f;
return cell;
結果如下:
您可以修改所需的角或創建其他路徑。
希望對您有所幫助。
誰說過[_tblView.layer setCornerRadius:10.0];
在分組樣式tableView中不起作用。
編寫此代碼,您將設置setCornerRadius也可以在分組的tableView中使用。
[_tblView setBackgroundView:nil];
[_tblView setBackgroundColor:[UIColor greenColor]];
[_tblView.layer setCornerRadius:10.0];
[_tblView.layer setCornerRadius:10.0];
不會為tableView的特定部分創建拐角半徑,這是用於設置整個tableView的拐角半徑。
將此添加到您的.h文件
#import <QuartzCore/QuartzCore.h>
並在您的代碼中使用以下代碼,
tblView.layer.cornerRadius=5.0f;
代替設置像元的角半徑,而是按如下方式設置像元的半徑:contentview:
cell.contentView.layer.cornerRadius = 10.0f;
cell.contentView.layer.borderColor = [UIColor blackColor].CGColor;
cell.contentView.layer.borderWidth = 3.0f;
在初始化單元格時放入上面的代碼。
在您的項目中添加quartzcore框架
import QuartzCore/QuartzCore.h to your .h file
self.tableView.layer.cornerRadius = 5.0f;
我認為您缺少這一行代碼:
[self.tableView.layer setMasksToBounds:YES];
首先,您需要使用QuartzCode框架Import the Framework AN和Declare .h File您要設置圖層效果的類。
並添加該方法
myTableView.layer.cornerRadius=5;
[myTableView setClipsToBounds:YES];
如果您想將角落半徑設置為單元格,請嘗試以下代碼
UITableViewCell.layer是CALayer類的一種,而CALayer類具有稱為cornerRadius的屬性。 因此,您可以將單元格的拐角半徑設置為休止符:
[cell.layer setCornerRadius:3.0];
試試這個代碼。
您可以這樣做。 它為我工作
UILabel *delLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 44)];
delLbl.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
delLbl.layer.cornerRadius = 10.0f;
delLbl.layer.borderWidth = 1.0f;
delLbl.layer.borderColor = [UIColor grayColor].CGColor;
delLbl.text = @"Cell Text";
delLbl.textAlignment = NSTextAlignmentCenter;
[cell.contentView addSubview:delLbl];
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
Return Cell;
我認為PrettyKit是您要找的東西。 完全可定制且快速。 https://github.com/vicpenap/PrettyKit可以嘗試一下。 應該做好這項工作。
嘗試這個:-
tableView.layer.cornerRadius=5.0f;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.